Search in sources :

Example 1 with NodeCoordinatesFilter

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

Aggregations

Edge (com.revolsys.geometry.graph.Edge)1 Node (com.revolsys.geometry.graph.Node)1 NodeDistanceComparator (com.revolsys.geometry.graph.comparator.NodeDistanceComparator)1 NodeCoordinatesFilter (com.revolsys.geometry.graph.filter.NodeCoordinatesFilter)1 PointOnLineSegment (com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)1 LineSegment (com.revolsys.geometry.model.segment.LineSegment)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1