Search in sources :

Example 46 with LineSegment

use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.

the class GeometryGraph method getBoundaryIntersection.

/**
 * Get the intersection between the line and the boundary of this geometry.
 *
 * @param line
 * @return
 */
public Geometry getBoundaryIntersection(final LineString line) {
    final List<Point> pointIntersections = new ArrayList<>();
    final List<LineString> lineIntersections = new ArrayList<>();
    final GeometryFactory geometryFactory = getGeometryFactory();
    final BoundingBox boundingBox = getBoundingBox(line);
    if (boundingBox.intersects(this.boundingBox)) {
        final LineString points = line;
        final int vertexCount = points.getVertexCount();
        final Point fromPoint = points.getPoint(0);
        final Point toPoint = points.getPoint(vertexCount - 1);
        Point previousPoint = fromPoint;
        for (int vertexIndex = 1; vertexIndex < vertexCount; vertexIndex++) {
            final Point nextPoint = points.getPoint(vertexIndex);
            final LineSegment line1 = new LineSegmentDoubleGF(getGeometryFactory(), previousPoint, nextPoint);
            final List<Edge<LineSegment>> edges = EdgeLessThanDistance.getEdges(this, line1, this.maxDistance);
            for (final Edge<LineSegment> edge2 : edges) {
                final LineSegment line2 = edge2.getObject();
                final Geometry segmentIntersection = line1.getIntersection(line2);
                if (segmentIntersection instanceof Point) {
                    final Point intersection = (Point) segmentIntersection;
                    if (intersection.equals(fromPoint) || intersection.equals(toPoint)) {
                        // Point intersection, make sure it's not at the start
                        final Node<LineSegment> node = findNode(intersection);
                        if (node == null) {
                            pointIntersections.add(geometryFactory.point(intersection));
                        } else {
                            final int degree = node.getDegree();
                            if (isStartPoint(node)) {
                                if (degree > 2) {
                                    // Intersection not at the start/end of the other line,
                                    // taking
                                    // into account loops
                                    pointIntersections.add(geometryFactory.point(intersection));
                                }
                            } else if (degree > 1) {
                                // Intersection not at the start/end of the other line
                                pointIntersections.add(geometryFactory.point(intersection));
                            }
                        }
                    } else {
                        // Intersection not at the start/end of the line
                        pointIntersections.add(geometryFactory.point(intersection));
                    }
                } else if (segmentIntersection instanceof LineSegment) {
                    lineIntersections.add((LineSegment) segmentIntersection);
                }
                for (final Point point : line1.vertices()) {
                    if (line2.distancePoint(point) < this.maxDistance) {
                        if (point.equals(fromPoint) || point.equals(toPoint)) {
                            // Point intersection, make sure it's not at the start
                            final double maxDistance1 = this.maxDistance;
                            for (final Node<LineSegment> node : this.getNodes(point, maxDistance1)) {
                                final int degree = node.getDegree();
                                if (isStartPoint(node)) {
                                    if (degree > 2) {
                                        // Intersection not at the start/end of the other line,
                                        // taking
                                        // into account loops
                                        pointIntersections.add(geometryFactory.point(point));
                                    }
                                } else if (degree > 1) {
                                    // Intersection not at the start/end of the other line
                                    pointIntersections.add(geometryFactory.point(point));
                                }
                            }
                        } else {
                            // Intersection not at the start/end of the line
                            pointIntersections.add(geometryFactory.point(point));
                        }
                    }
                }
            }
            previousPoint = nextPoint;
        }
    }
    if (lineIntersections.isEmpty()) {
        return geometryFactory.punctual(pointIntersections);
    } else {
        final List<LineString> mergedLines = LineMerger.merge(lineIntersections);
        final Lineal multiLine = geometryFactory.lineal(mergedLines);
        if (pointIntersections.isEmpty()) {
            return multiLine;
        } else {
            final Punctual multiPoint = geometryFactory.punctual(pointIntersections);
            return multiPoint.union(multiLine);
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) LineSegmentDoubleGF(com.revolsys.geometry.model.segment.LineSegmentDoubleGF) Geometry(com.revolsys.geometry.model.Geometry) Punctual(com.revolsys.geometry.model.Punctual) Lineal(com.revolsys.geometry.model.Lineal) LineString(com.revolsys.geometry.model.LineString) BoundingBox(com.revolsys.geometry.model.BoundingBox) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 47 with LineSegment

use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.

the class EdgeLessThanDistance method test.

@Override
public boolean test(final Edge<LineSegment> edge) {
    final LineSegment lineSegment = edge.getObject();
    final double distance = lineSegment.distance(this.lineSegment);
    if (distance <= this.maxDistance) {
        return true;
    } else {
        return false;
    }
}
Also used : LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 48 with LineSegment

use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.

the class LineStringGraph method getPointsOnEdges.

public Map<Edge<LineSegment>, List<Node<LineSegment>>> getPointsOnEdges(final Graph<LineSegment> graph1, final double tolerance) {
    final Map<Edge<LineSegment>, List<Node<LineSegment>>> pointsOnEdge1 = new HashMap<>();
    for (final Edge<LineSegment> edge : getEdges()) {
        final Node<LineSegment> fromNode = edge.getFromNode();
        final Node<LineSegment> toNode = edge.getToNode();
        final LineSegment lineSegment = edge.getObject();
        final PointOnLineSegment coordinatesFilter = new PointOnLineSegment(lineSegment, tolerance);
        final NodeCoordinatesFilter<LineSegment> nodeFilter = new NodeCoordinatesFilter<>(coordinatesFilter);
        final NodeDistanceComparator<LineSegment> comparator = new NodeDistanceComparator<>(fromNode);
        final List<Node<LineSegment>> nodes = graph1.getNodes(nodeFilter, comparator);
        for (final Iterator<Node<LineSegment>> iterator = nodes.iterator(); iterator.hasNext(); ) {
            final Node<LineSegment> node = iterator.next();
            if (node.equals(2, fromNode)) {
                iterator.remove();
            } else if (node.equals(2, toNode)) {
                iterator.remove();
            }
        }
        if (!nodes.isEmpty()) {
            pointsOnEdge1.put(edge, nodes);
        }
    }
    return pointsOnEdge1;
}
Also used : NodeCoordinatesFilter(com.revolsys.geometry.graph.filter.NodeCoordinatesFilter) HashMap(java.util.HashMap) Node(com.revolsys.geometry.graph.Node) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment) NodeDistanceComparator(com.revolsys.geometry.graph.comparator.NodeDistanceComparator) ArrayList(java.util.ArrayList) List(java.util.List) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Example 49 with LineSegment

use of com.revolsys.geometry.model.segment.LineSegment 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)

Example 50 with LineSegment

use of com.revolsys.geometry.model.segment.LineSegment in project com.revolsys.open by revolsys.

the class LineStringGraph method hasTouchingEdges.

public boolean hasTouchingEdges(final Node<LineSegment> node) {
    final GeometryFactory precisionModel = getPrecisionModel();
    final List<Edge<LineSegment>> edges = getEdges(node, precisionModel.getScaleXY());
    for (final Edge<LineSegment> edge : edges) {
        final Point lineStart = edge.getFromNode();
        final Point lineEnd = edge.getToNode();
        if (LineSegmentUtil.isPointOnLineMiddle(precisionModel, lineStart, lineEnd, node)) {
            return true;
        }
    }
    return false;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Point(com.revolsys.geometry.model.Point) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Aggregations

LineSegment (com.revolsys.geometry.model.segment.LineSegment)61 Point (com.revolsys.geometry.model.Point)34 Edge (com.revolsys.geometry.graph.Edge)19 LineSegmentDouble (com.revolsys.geometry.model.segment.LineSegmentDouble)14 LineSegmentDoubleGF (com.revolsys.geometry.model.segment.LineSegmentDoubleGF)13 Geometry (com.revolsys.geometry.model.Geometry)12 PointOnLineSegment (com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)11 ArrayList (java.util.ArrayList)10 LineString (com.revolsys.geometry.model.LineString)9 Node (com.revolsys.geometry.graph.Node)7 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)6 EdgeAttributeValueComparator (com.revolsys.geometry.graph.comparator.EdgeAttributeValueComparator)5 BoundingBox (com.revolsys.geometry.model.BoundingBox)4 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)4 List (java.util.List)4 EdgeObjectFilter (com.revolsys.geometry.graph.filter.EdgeObjectFilter)2 LineStringGraph (com.revolsys.geometry.graph.linestring.LineStringGraph)2 Polygon (com.revolsys.geometry.model.Polygon)2 Vertex (com.revolsys.geometry.model.vertex.Vertex)2 Shape (java.awt.Shape)2