use of com.revolsys.geometry.model.segment.LineSegment 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.segment.LineSegment 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.segment.LineSegment in project com.revolsys.open by revolsys.
the class LineStringGraph method removeDuplicateEdges.
private void removeDuplicateEdges() {
final Comparator<Edge<LineSegment>> comparator = new EdgeAttributeValueComparator<>(INDEX);
forEachEdge(comparator, (edge) -> {
final Node<LineSegment> fromNode = edge.getFromNode();
final Node<LineSegment> toNode = edge.getToNode();
final Collection<Edge<LineSegment>> edges = fromNode.getEdgesTo(toNode);
final int duplicateCount = edges.size();
if (duplicateCount > 1) {
edges.remove(edge);
Edge.remove(edges);
}
});
}
use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.
the class LineStringGraph method splitEdgesCloseToNodes.
public void splitEdgesCloseToNodes() {
double distance = 0;
final double scaleXY = this.geometryFactory.getScaleXY();
if (scaleXY > 0) {
distance = 1 / scaleXY;
}
for (final Node<LineSegment> node : getNodes()) {
final List<Edge<LineSegment>> edges = getEdges(node, distance);
edges.removeAll(node.getEdges());
if (!edges.isEmpty()) {
for (final Edge<LineSegment> edge : edges) {
final LineSegment line = edge.getObject();
if (line.isPointOnLineMiddle(node, distance)) {
edge.split(node);
}
}
}
}
}
use of com.revolsys.geometry.model.segment.LineSegment 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);
}
Aggregations