Search in sources :

Example 6 with Edge

use of com.revolsys.geometry.graph.Edge 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)

Example 7 with Edge

use of com.revolsys.geometry.graph.Edge in project com.revolsys.open by revolsys.

the class LineMatchGraph method getMatchLength.

public double getMatchLength(final Node<LineSegmentMatch> node, final boolean direction, final int index1, final int index2) {
    List<Edge<LineSegmentMatch>> edges;
    if (direction) {
        edges = node.getOutEdges();
    } else {
        edges = node.getInEdges();
    }
    for (final Edge<LineSegmentMatch> edge : edges) {
        final LineSegmentMatch lineSegmentMatch = edge.getObject();
        if (lineSegmentMatch.hasMatches(index1, index2)) {
            final LineSegment segment = lineSegmentMatch.getSegment(index2);
            final double length = segment.getLength();
            final Node<LineSegmentMatch> nextNode = edge.getOppositeNode(node);
            return length + getMatchLength(nextNode, direction, index1, index2);
        }
    }
    return 0;
}
Also used : Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 8 with Edge

use of com.revolsys.geometry.graph.Edge in project com.revolsys.open by revolsys.

the class LineMatchGraph method getNonMatchedLines.

public Lineal getNonMatchedLines(final int index1, final int index2) {
    final List<LineString> lines = new ArrayList<>();
    final Set<Edge<LineSegmentMatch>> processedEdges = new HashSet<>();
    for (Node<LineSegmentMatch> currentNode : getStartNodes(index1)) {
        final List<Point> coordinates = new ArrayList<>();
        while (currentNode != null) {
            Node<LineSegmentMatch> nextNode = null;
            final List<Edge<LineSegmentMatch>> edges = currentNode.getOutEdges();
            for (final Edge<LineSegmentMatch> edge : edges) {
                final LineSegmentMatch lineSegmentMatch = edge.getObject();
                if (lineSegmentMatch.hasSegment(index1) && !processedEdges.contains(edge)) {
                    if (!lineSegmentMatch.hasMatches(index1, index2)) {
                        if (coordinates.isEmpty()) {
                            final Point startCoordinate = currentNode;
                            coordinates.add(startCoordinate);
                        }
                        final Node<LineSegmentMatch> toNode = edge.getToNode();
                        final Point toCoordinate = toNode;
                        coordinates.add(toCoordinate);
                    } else {
                        newLine(lines, coordinates);
                        coordinates.clear();
                    }
                    processedEdges.add(edge);
                    nextNode = edge.getToNode();
                }
            }
            currentNode = nextNode;
        }
        newLine(lines, coordinates);
    }
    return this.geometryFactory.lineal(lines);
}
Also used : LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Edge(com.revolsys.geometry.graph.Edge) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 9 with Edge

use of com.revolsys.geometry.graph.Edge in project com.revolsys.open by revolsys.

the class LineMatchGraph method getOverlappingMatches.

public Lineal getOverlappingMatches() {
    final List<LineString> overlappingLines = new ArrayList<>();
    final Set<Edge<LineSegmentMatch>> processedEdges = new HashSet<>();
    for (Node<LineSegmentMatch> currentNode : getStartNodes(0)) {
        while (currentNode != null) {
            Node<LineSegmentMatch> nextNode = null;
            final List<Edge<LineSegmentMatch>> edges = currentNode.getOutEdges();
            for (final Edge<LineSegmentMatch> edge : edges) {
                final LineSegmentMatch lineSegmentMatch = edge.getObject();
                if (lineSegmentMatch.hasSegment(0) && !processedEdges.contains(edge)) {
                    if (lineSegmentMatch.getMatchCount(0) > 2) {
                        for (int i = 1; i < lineSegmentMatch.getSegmentCount() && lineSegmentMatch.getMatchCount(0) > 2; i++) {
                            if (lineSegmentMatch.hasSegment(i)) {
                                if (!hasMatch(currentNode, false, 0, i)) {
                                    final Node<LineSegmentMatch> toNode = edge.getToNode();
                                    if (!hasMatch(toNode, true, 0, i)) {
                                        lineSegmentMatch.removeSegment(i);
                                    } else {
                                        final double matchLength = getMatchLength(currentNode, false, 0, i);
                                        final double duplicateMatchLength = getDuplicateMatchLength(currentNode, true, 0, i);
                                        if (matchLength + duplicateMatchLength <= 2) {
                                            lineSegmentMatch.removeSegment(i);
                                        }
                                    }
                                }
                            }
                        }
                        if (lineSegmentMatch.getMatchCount(0) > 2) {
                            overlappingLines.add(lineSegmentMatch.getLine());
                        }
                    }
                    processedEdges.add(edge);
                    nextNode = edge.getToNode();
                }
            }
            currentNode = nextNode;
        }
    }
    final Lineal lines = this.geometryFactory.lineal(overlappingLines);
    return lines;
}
Also used : ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Lineal(com.revolsys.geometry.model.Lineal) LineString(com.revolsys.geometry.model.LineString) Edge(com.revolsys.geometry.graph.Edge) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 10 with Edge

use of com.revolsys.geometry.graph.Edge in project com.revolsys.open by revolsys.

the class LineMatchGraph method getMatchedLinesList.

public List<LineString> getMatchedLinesList(final int index1, final int index2) {
    final List<LineString> lines = new ArrayList<>();
    final Set<Edge<LineSegmentMatch>> processedEdges = new HashSet<>();
    for (Node<LineSegmentMatch> currentNode : getStartNodes(index2)) {
        final List<Point> coordinates = new ArrayList<>();
        while (currentNode != null) {
            Node<LineSegmentMatch> nextNode = null;
            final List<Edge<LineSegmentMatch>> edges = currentNode.getOutEdges();
            for (final Edge<LineSegmentMatch> edge : edges) {
                final LineSegmentMatch lineSegmentMatch = edge.getObject();
                if (lineSegmentMatch.hasSegment(index2) && !processedEdges.contains(edge)) {
                    if (lineSegmentMatch.hasMatches(index1, index2)) {
                        if (coordinates.isEmpty()) {
                            final Point startCoordinate = currentNode;
                            coordinates.add(startCoordinate);
                        }
                        final Node<LineSegmentMatch> toNode = edge.getToNode();
                        final Point toCoordinate = toNode;
                        coordinates.add(toCoordinate);
                    } else {
                        newLine(lines, coordinates);
                        coordinates.clear();
                    }
                    processedEdges.add(edge);
                    nextNode = edge.getToNode();
                }
            }
            currentNode = nextNode;
        }
        newLine(lines, coordinates);
    }
    return lines;
}
Also used : LineString(com.revolsys.geometry.model.LineString) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Edge(com.revolsys.geometry.graph.Edge) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

Edge (com.revolsys.geometry.graph.Edge)40 LineString (com.revolsys.geometry.model.LineString)22 Point (com.revolsys.geometry.model.Point)21 LineSegment (com.revolsys.geometry.model.segment.LineSegment)19 ArrayList (java.util.ArrayList)14 BoundingBox (com.revolsys.geometry.model.BoundingBox)10 PointOnLineSegment (com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)9 Node (com.revolsys.geometry.graph.Node)8 Geometry (com.revolsys.geometry.model.Geometry)8 LinkedHashSet (java.util.LinkedHashSet)7 Record (com.revolsys.record.Record)6 CreateListVisitor (com.revolsys.visitor.CreateListVisitor)6 HashSet (java.util.HashSet)6 EdgeAttributeValueComparator (com.revolsys.geometry.graph.comparator.EdgeAttributeValueComparator)5 List (java.util.List)5 EdgeObjectFilter (com.revolsys.geometry.graph.filter.EdgeObjectFilter)4 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)4 LineSegmentDoubleGF (com.revolsys.geometry.model.segment.LineSegmentDoubleGF)4 EdgeTypeNameFilter (com.revolsys.geometry.graph.filter.EdgeTypeNameFilter)2 LineStringGraph (com.revolsys.geometry.graph.linestring.LineStringGraph)2