use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class LineStringGraph method isSimple.
public boolean isSimple() {
for (final Node<LineSegment> node : getNodes()) {
if (node.getDegree() > 2) {
return false;
}
}
for (final Edge<LineSegment> edge : getEdges()) {
final LineSegment line = edge.getObject();
final EdgeObjectFilter<LineSegment> filter = new EdgeObjectFilter<>(new LineSegmentIntersectingFilter(line));
final List<Edge<LineSegment>> edges = getEdges(line, filter);
for (final Edge<LineSegment> edge2 : edges) {
final LineSegment line2 = edge2.getObject();
final Geometry intersections = line.getIntersection(line2);
if (intersections instanceof LineSegment) {
return false;
} else if (intersections instanceof Point) {
if (edge.getCommonNodes(edge2).isEmpty()) {
return false;
}
}
}
}
return true;
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class LineStringGraph method getSelfIntersections.
public Geometry getSelfIntersections() {
final Set<Point> intersectionPoints = new HashSet<>();
for (int i = 0; i < this.points.getVertexCount(); i++) {
final Point point = this.points.getPoint(i);
final Node<LineSegment> node = getNode(point);
if (node.getDegree() > 2 || hasTouchingEdges(node)) {
intersectionPoints.add(point);
}
}
forEachEdge((edge1) -> {
final LineSegment lineSegment1 = edge1.getObject();
forEachEdge(edge1, (edge2) -> {
if (edge1 != edge2) {
final LineSegment lineSegment2 = edge2.getObject();
final Geometry intersections = ((LineSegment) lineSegment1.convertGeometry(getGeometryFactory())).getIntersection(lineSegment2);
for (final Point intersection : intersections.vertices()) {
if (!lineSegment1.isEndPoint(intersection) && !lineSegment2.isEndPoint(intersection)) {
intersectionPoints.add(intersection);
}
}
}
});
});
return this.geometryFactory.punctual(intersectionPoints);
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class LineStringRelate method getOverlap.
public Lineal getOverlap() {
final List<List<Point>> intersections = new ArrayList<>();
final LineString points1 = this.line1;
final List<Point> currentCoordinates = new ArrayList<>();
Node<LineSegment> previousNode = this.graph1.getNode(this.fromPoint1);
do {
final List<Edge<LineSegment>> outEdges = previousNode.getOutEdges();
if (outEdges.isEmpty()) {
previousNode = null;
} else if (outEdges.size() > 1) {
System.err.println("Cannot handle overlaps\n" + getLine1() + "\n " + getLine2());
final GeometryFactory factory = this.line1.getGeometryFactory();
return factory.lineString();
} else {
final Edge<LineSegment> edge = outEdges.get(0);
final LineSegment line = edge.getObject();
final Node<LineSegment> nextNode = edge.getToNode();
if (this.graph2.hasEdgeBetween(previousNode, nextNode)) {
if (currentCoordinates.size() == 0) {
currentCoordinates.add(line.getPoint(0));
}
currentCoordinates.add(line.getPoint(1));
} else {
if (currentCoordinates.size() > 0) {
final List<Point> points = new ArrayList<>();
intersections.add(points);
currentCoordinates.clear();
}
}
previousNode = nextNode;
}
} while (previousNode != null && !previousNode.equals(2, this.fromPoint1));
if (currentCoordinates.size() > 0) {
final List<Point> points = new ArrayList<>();
intersections.add(points);
}
final GeometryFactory factory = this.line1.getGeometryFactory();
return factory.lineal(intersections);
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class GeometryGraph method insertBoundaryPoint.
/**
* Adds candidate boundary points using the current {@link BoundaryNodeRule}.
* This is used to add the boundary
* points of dim-1 geometries (Curves/MultiCurves).
*/
private void insertBoundaryPoint(final int argIndex, final Point point) {
final NodeMap nodes = getNodeMap();
final Node n = nodes.addNode(point);
// nodes always have labels
final Label lbl = n.getLabel();
// the new point to insert is on a boundary
int boundaryCount = 1;
// determine the current location for the point (if any)
Location loc = Location.NONE;
loc = lbl.getLocation(argIndex, Position.ON);
if (loc == Location.BOUNDARY) {
boundaryCount++;
}
// determine the boundary status of the point according to the Boundary
// Determination Rule
final Location newLoc = determineBoundary(this.boundaryNodeRule, boundaryCount);
lbl.setLocation(argIndex, newLoc);
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class GeometryGraph method addLineString.
private void addLineString(final LineString line) {
final LineString cleanLine = line.removeDuplicatePoints();
final int cleanVertexCount = cleanLine.getVertexCount();
if (cleanVertexCount < 2 || cleanLine.isEmpty()) {
this.hasTooFewPoints = true;
this.invalidPoint = cleanLine.getPoint(0);
return;
} else {
// add the edge for the LineString
// line edges do not have locations for their left and right sides
final Edge e = new Edge(cleanLine, new Label(this.argIndex, Location.INTERIOR));
this.lineEdgeMap.put(line, e);
insertEdge(e);
/**
* Add the boundary points of the LineString, if any.
* Even if the LineString is closed, add both points as if they were endpoints.
* This allows for the case that the node already exists and is a boundary point.
*/
insertBoundaryPoint(this.argIndex, cleanLine.getPoint(0));
insertBoundaryPoint(this.argIndex, cleanLine.getPoint(cleanVertexCount - 1));
}
}
Aggregations