Search in sources :

Example 91 with LineString

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

Example 92 with LineString

use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.

the class GraphProcessor method process.

@Override
protected void process(final Channel<Record> in, final Channel<Record> out, final Record object) {
    final Geometry geometry = object.getGeometry();
    if (geometry instanceof LineString) {
        final LineString line = (LineString) geometry;
        this.graph.addEdge(object, line);
    } else {
        if (out != null) {
            out.write(object);
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LineString(com.revolsys.geometry.model.LineString)

Example 93 with LineString

use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.

the class BoundingBoxIntersectsEdgeVisitor method getEdges.

public static <T> List<Edge<T>> getEdges(final Graph<T> graph, final Edge<T> edge, final double maxDistance) {
    final CreateListVisitor<Edge<T>> results = new CreateListVisitor<>();
    final LineString line = edge.getLineString();
    BoundingBox boundingBox = line.getBoundingBox();
    boundingBox = boundingBox.expand(maxDistance);
    final BoundingBoxIntersectsEdgeVisitor<T> visitor = new BoundingBoxIntersectsEdgeVisitor<>(boundingBox, results);
    final IdObjectIndex<Edge<T>> index = graph.getEdgeIndex();
    index.forEach(boundingBox, visitor);
    final List<Edge<T>> list = results.getList();
    list.remove(edge);
    return list;
}
Also used : LineString(com.revolsys.geometry.model.LineString) BoundingBox(com.revolsys.geometry.model.BoundingBox) CreateListVisitor(com.revolsys.visitor.CreateListVisitor) Edge(com.revolsys.geometry.graph.Edge)

Example 94 with LineString

use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.

the class EdgeIntersectsLinearlyEdgeVisitor method accept.

@Override
public void accept(final Edge<T> edge2) {
    if (edge2 != this.edge) {
        final LineString line1 = this.edge.getLineString();
        final LineString line2 = edge2.getLineString();
        final BoundingBox envelope1 = line1.getBoundingBox();
        final BoundingBox envelope2 = line2.getBoundingBox();
        if (envelope1.intersects(envelope2)) {
            final IntersectionMatrix relate = line1.relate(line2);
            if (relate.get(0, 0) == Dimension.L) {
                this.matchVisitor.accept(edge2);
            }
        }
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) BoundingBox(com.revolsys.geometry.model.BoundingBox) IntersectionMatrix(com.revolsys.geometry.model.IntersectionMatrix)

Example 95 with LineString

use of com.revolsys.geometry.model.LineString in project com.revolsys.open by revolsys.

the class EdgeIntersectsLinearlyEdgeVisitor method getEdges.

public static <T> List<Edge<T>> getEdges(final Graph<T> graph, final Edge<T> edge) {
    final CreateListVisitor<Edge<T>> results = new CreateListVisitor<>();
    final LineString line = edge.getLineString();
    final BoundingBox env = line.getBoundingBox();
    final IdObjectIndex<Edge<T>> index = graph.getEdgeIndex();
    index.forEach(env, new EdgeIntersectsLinearlyEdgeVisitor<>(edge, results));
    final List<Edge<T>> edges = results.getList();
    Collections.sort(edges);
    return edges;
}
Also used : LineString(com.revolsys.geometry.model.LineString) BoundingBox(com.revolsys.geometry.model.BoundingBox) CreateListVisitor(com.revolsys.visitor.CreateListVisitor) Edge(com.revolsys.geometry.graph.Edge)

Aggregations

LineString (com.revolsys.geometry.model.LineString)380 Point (com.revolsys.geometry.model.Point)184 Geometry (com.revolsys.geometry.model.Geometry)65 ArrayList (java.util.ArrayList)62 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)51 Polygon (com.revolsys.geometry.model.Polygon)37 LineStringGraph (com.revolsys.geometry.graph.linestring.LineStringGraph)24 Edge (com.revolsys.geometry.graph.Edge)22 List (java.util.List)22 BoundingBox (com.revolsys.geometry.model.BoundingBox)20 Lineal (com.revolsys.geometry.model.Lineal)20 Test (org.junit.Test)20 LinearRing (com.revolsys.geometry.model.LinearRing)19 Record (com.revolsys.record.Record)17 Iterator (java.util.Iterator)14 LineStringEditor (com.revolsys.geometry.model.editor.LineStringEditor)13 Punctual (com.revolsys.geometry.model.Punctual)12 LineStringDouble (com.revolsys.geometry.model.impl.LineStringDouble)12 LineSegment (com.revolsys.geometry.model.segment.LineSegment)10 Polygonal (com.revolsys.geometry.model.Polygonal)9