Search in sources :

Example 1 with Node

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

the class LineStringGraph method getLines.

public List<LineString> getLines() {
    removeDuplicateEdges();
    final EdgeAttributeValueComparator<LineSegment> comparator = new EdgeAttributeValueComparator<>("INDEX");
    final List<LineString> lines = new ArrayList<>();
    final List<Point> points = new ArrayList<>();
    final Consumer<Edge<LineSegment>> action = new Consumer<Edge<LineSegment>>() {

        private Node<LineSegment> previousNode = null;

        @Override
        public void accept(final Edge<LineSegment> edge) {
            final LineSegment lineSegment = edge.getObject();
            if (lineSegment.getLength() > 0) {
                final Node<LineSegment> fromNode = edge.getFromNode();
                final Node<LineSegment> toNode = edge.getToNode();
                if (this.previousNode == null) {
                    points.add(lineSegment.getPoint(0));
                    points.add(lineSegment.getPoint(1));
                } else if (fromNode == this.previousNode) {
                    if (edge.getLength() > 0) {
                        points.add(toNode);
                    }
                } else {
                    if (points.size() > 1) {
                        final LineString line = LineStringGraph.this.geometryFactory.lineString(points);
                        lines.add(line);
                    }
                    points.clear();
                    ;
                    points.add(lineSegment.getPoint(0));
                    points.add(lineSegment.getPoint(1));
                }
                if (points.size() > 1) {
                    final int toDegree = toNode.getDegree();
                    if (toDegree != 2) {
                        final LineString line = LineStringGraph.this.geometryFactory.lineString(points);
                        lines.add(line);
                        points.clear();
                        ;
                        points.add(toNode);
                    }
                }
                this.previousNode = toNode;
            }
        }
    };
    forEachEdge(comparator, action);
    if (points.size() > 1) {
        final LineString line = this.geometryFactory.lineString(points);
        lines.add(line);
    }
    return lines;
}
Also used : EdgeAttributeValueComparator(com.revolsys.geometry.graph.comparator.EdgeAttributeValueComparator) Node(com.revolsys.geometry.graph.Node) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) Consumer(java.util.function.Consumer) LineString(com.revolsys.geometry.model.LineString) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Example 2 with Node

use of com.revolsys.geometry.graph.Node 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 3 with Node

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

the class LineMatchGraph method add.

private void add(final LineString line, final int index) {
    if (line.getLength() > 0) {
        final LineString coords = line;
        final Point coordinate0 = coords.getPoint(0);
        final Node<LineSegmentMatch> node = getNode(coordinate0);
        final Set<Node<LineSegmentMatch>> indexStartNodes = getStartNodes(index);
        indexStartNodes.add(node);
        Point previousCoordinate = coordinate0;
        for (int i = 1; i < coords.getVertexCount(); i++) {
            final Point coordinate = coords.getPoint(i);
            final LineSegment segment = new LineSegmentDoubleGF(this.geometryFactory, previousCoordinate, coordinate);
            if (segment.getLength() > 0) {
                add(previousCoordinate, coordinate, segment, index);
            }
            previousCoordinate = coordinate;
        }
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) Node(com.revolsys.geometry.graph.Node) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) LineSegmentDoubleGF(com.revolsys.geometry.model.segment.LineSegmentDoubleGF) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 4 with Node

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

the class NodeLessThanDistanceOfGeometryVisitor method getNodes.

public static <T> List<Node<T>> getNodes(final Graph<T> graph, final Geometry geometry, final double maxDistance) {
    if (geometry == null) {
        return Collections.emptyList();
    } else {
        final CreateListVisitor<Node<T>> results = new CreateListVisitor<>();
        BoundingBox env = geometry.getBoundingBox();
        env = env.expand(maxDistance);
        final IdObjectIndex<Node<T>> index = graph.getNodeIndex();
        final NodeLessThanDistanceOfGeometryVisitor<T> visitor = new NodeLessThanDistanceOfGeometryVisitor<>(geometry, maxDistance, results);
        index.forEach(env, visitor);
        return results.getList();
    }
}
Also used : Node(com.revolsys.geometry.graph.Node) BoundingBox(com.revolsys.geometry.model.BoundingBox) CreateListVisitor(com.revolsys.visitor.CreateListVisitor)

Example 5 with Node

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

the class OnLineNodeVisitor method getNodes.

public static <T> List<Node<T>> getNodes(final Graph<T> graph, final LineString line, final double maxDistance) {
    if (line == null) {
        return Collections.emptyList();
    } else {
        final CreateListVisitor<Node<T>> results = new CreateListVisitor<>();
        BoundingBox env = line.getBoundingBox();
        env = env.expand(maxDistance);
        final IdObjectIndex<Node<T>> index = graph.getNodeIndex();
        final OnLineNodeVisitor<T> visitor = new OnLineNodeVisitor<>(line, results);
        index.forEach(env, visitor);
        return results.getList();
    }
}
Also used : Node(com.revolsys.geometry.graph.Node) BoundingBox(com.revolsys.geometry.model.BoundingBox) CreateListVisitor(com.revolsys.visitor.CreateListVisitor)

Aggregations

Node (com.revolsys.geometry.graph.Node)13 Edge (com.revolsys.geometry.graph.Edge)8 LineString (com.revolsys.geometry.model.LineString)8 LineSegment (com.revolsys.geometry.model.segment.LineSegment)7 Point (com.revolsys.geometry.model.Point)6 ArrayList (java.util.ArrayList)6 List (java.util.List)4 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)3 EdgeAttributeValueComparator (com.revolsys.geometry.graph.comparator.EdgeAttributeValueComparator)2 BoundingBox (com.revolsys.geometry.model.BoundingBox)2 Geometry (com.revolsys.geometry.model.Geometry)2 PointOnLineSegment (com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)2 CreateListVisitor (com.revolsys.visitor.CreateListVisitor)2 HashMap (java.util.HashMap)2 Consumer (java.util.function.Consumer)2 DataType (com.revolsys.datatype.DataType)1 RecordGraph (com.revolsys.geometry.graph.RecordGraph)1 NodeDistanceComparator (com.revolsys.geometry.graph.comparator.NodeDistanceComparator)1 NodeCoordinatesFilter (com.revolsys.geometry.graph.filter.NodeCoordinatesFilter)1 LineStringGraph (com.revolsys.geometry.graph.linestring.LineStringGraph)1