Search in sources :

Example 6 with LineSegment

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;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) EdgeObjectFilter(com.revolsys.geometry.graph.filter.EdgeObjectFilter) 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)

Example 7 with LineSegment

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);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) HashSet(java.util.HashSet) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Example 8 with LineSegment

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);
        }
    });
}
Also used : EdgeAttributeValueComparator(com.revolsys.geometry.graph.comparator.EdgeAttributeValueComparator) Edge(com.revolsys.geometry.graph.Edge) Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Example 9 with LineSegment

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);
                }
            }
        }
    }
}
Also used : Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Example 10 with LineSegment

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);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Node(com.revolsys.geometry.graph.Node) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) LineString(com.revolsys.geometry.model.LineString) List(java.util.List) ArrayList(java.util.ArrayList) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

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