Search in sources :

Example 1 with CrossingLineSegmentFilter

use of com.revolsys.geometry.model.coordinates.filter.CrossingLineSegmentFilter 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);
            }
        }
    });
}
Also used : EdgeAttributeValueComparator(com.revolsys.geometry.graph.comparator.EdgeAttributeValueComparator) EdgeObjectFilter(com.revolsys.geometry.graph.filter.EdgeObjectFilter) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Geometry(com.revolsys.geometry.model.Geometry) CrossingLineSegmentFilter(com.revolsys.geometry.model.coordinates.filter.CrossingLineSegmentFilter) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Aggregations

Edge (com.revolsys.geometry.graph.Edge)1 EdgeAttributeValueComparator (com.revolsys.geometry.graph.comparator.EdgeAttributeValueComparator)1 EdgeObjectFilter (com.revolsys.geometry.graph.filter.EdgeObjectFilter)1 Geometry (com.revolsys.geometry.model.Geometry)1 Point (com.revolsys.geometry.model.Point)1 CrossingLineSegmentFilter (com.revolsys.geometry.model.coordinates.filter.CrossingLineSegmentFilter)1 PointOnLineSegment (com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)1 LineSegment (com.revolsys.geometry.model.segment.LineSegment)1 ArrayList (java.util.ArrayList)1