use of com.revolsys.geometry.graph.filter.EdgeObjectFilter 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.graph.filter.EdgeObjectFilter in project com.revolsys.open by revolsys.
the class LineStringGraph method splitCrossingEdges.
public void splitCrossingEdges() {
final Comparator<Edge<LineSegment>> comparator = new EdgeAttributeValueComparator<>(INDEX);
forEachEdge(comparator, (edge) -> {
final LineSegment line1 = edge.getObject();
final Predicate<LineSegment> lineFilter = new CrossingLineSegmentFilter(line1);
final Predicate<Edge<LineSegment>> filter = new EdgeObjectFilter<>(lineFilter);
final List<Edge<LineSegment>> edges = getEdges(line1, filter);
if (!edges.isEmpty()) {
final List<Point> points = new ArrayList<>();
for (final Edge<LineSegment> edge2 : edges) {
final LineSegment line2 = edge2.getObject();
final Geometry intersections = line1.getIntersection(line2);
if (intersections instanceof Point) {
final Point intersection = (Point) intersections;
points.add(intersection);
edge2.split(intersection);
}
}
if (!points.isEmpty()) {
edge.splitEdge(points);
}
}
});
}
use of com.revolsys.geometry.graph.filter.EdgeObjectFilter in project com.revolsys.open by revolsys.
the class LinearIntersectionNotEqualLineEdgeCleanupVisitor method accept.
@Override
public void accept(final Edge<Record> edge) {
final String typePath = edge.getTypeName();
final Graph<Record> graph = edge.getGraph();
final LineString line = edge.getLineString();
Predicate<Edge<Record>> attributeAndGeometryFilter = new EdgeTypeNameFilter<>(typePath);
final Predicate<Edge<Record>> filter = getPredicate();
if (filter != null) {
attributeAndGeometryFilter = attributeAndGeometryFilter.and(filter);
}
final Predicate<Record> notEqualLineFilter = new RecordGeometryFilter<>(new EqualFilter<>(line)).negate();
final RecordGeometryFilter<LineString> linearIntersectionFilter = new RecordGeometryFilter<>(new LinearIntersectionFilter(line));
attributeAndGeometryFilter = attributeAndGeometryFilter.and(new EdgeObjectFilter<>(notEqualLineFilter.and(linearIntersectionFilter)));
final List<Edge<Record>> intersectingEdges = graph.getEdges(line, attributeAndGeometryFilter);
if (!intersectingEdges.isEmpty()) {
if (intersectingEdges.size() == 1 && line.getLength() > 10) {
if (line.getVertexCount() > 2) {
final Edge<Record> edge2 = intersectingEdges.get(0);
final LineString line2 = edge2.getLineString();
if (middleCoordinatesEqual(line, line2)) {
final boolean firstEqual = line.equalsVertex(2, 0, line2, 0);
if (!firstEqual) {
final Node<Record> fromNode1 = edge.getFromNode();
final Node<Record> fromNode2 = edge2.getFromNode();
if (fromNode1.distancePoint(fromNode2) < 2) {
graph.moveNodesToMidpoint(typePath, fromNode1, fromNode2);
return;
}
}
final boolean lastEqual = line.equalsVertex(2, line.getVertexCount() - 1, line2, line.getVertexCount() - 1);
if (!lastEqual) {
final Node<Record> toNode1 = edge.getToNode();
final Node<Record> toNode2 = edge2.getToNode();
if (toNode1.distancePoint(toNode2) < 2) {
graph.moveNodesToMidpoint(typePath, toNode1, toNode2);
return;
}
}
}
}
}
Logs.error(this, "Has intersecting edges " + line);
}
}
use of com.revolsys.geometry.graph.filter.EdgeObjectFilter in project com.revolsys.open by revolsys.
the class EqualTypeAndLineEdgeCleanupVisitor method accept.
@Override
public void accept(final Edge<Record> edge) {
if (edge.getProperty(EDGE_PROCESSED) == null) {
final String typePath = edge.getTypeName();
final Graph<Record> graph = edge.getGraph();
final LineString line = edge.getLineString();
Predicate<Edge<Record>> attributeAndGeometryFilter = new EdgeTypeNameFilter<>(typePath);
final Predicate<Edge<Record>> filter = getPredicate();
if (filter != null) {
attributeAndGeometryFilter = attributeAndGeometryFilter.and(filter);
}
final Predicate<Record> equalLineFilter = new RecordGeometryFilter<>(new LineEqualIgnoreDirectionFilter(line, 2));
final EdgeObjectFilter<Record> edgeFilter = new EdgeObjectFilter<>(equalLineFilter);
attributeAndGeometryFilter = attributeAndGeometryFilter.and(edgeFilter);
final List<Edge<Record>> equalEdges;
if (getComparator() == null) {
equalEdges = graph.getEdges(line, attributeAndGeometryFilter);
} else {
equalEdges = graph.getEdges(line, attributeAndGeometryFilter, getComparator());
}
processEqualEdges(equalEdges);
}
}
Aggregations