Search in sources :

Example 1 with NodeDistanceComparator

use of com.revolsys.geometry.graph.comparator.NodeDistanceComparator in project com.revolsys.open by revolsys.

the class Graph method findNodes.

/**
 * Find all the nodes <= the distance of the edge, that are "on" the line.
 *
 * @param edge The edge.
 * @param distance The distance.
 * @return The nodes
 * @see IsPointOnLineEdgeFilter
 */
public List<Node<T>> findNodes(final Edge<T> edge, final double distance) {
    final IsPointOnLineEdgeFilter<T> filter = new IsPointOnLineEdgeFilter<>(edge, distance);
    final Node<T> fromNode = edge.getFromNode();
    final Comparator<Node<T>> comparator = new NodeDistanceComparator<>(fromNode);
    final BoundingBox boundingBox = filter.getEnvelope();
    return getNodes(boundingBox, filter, comparator);
}
Also used : NodeDistanceComparator(com.revolsys.geometry.graph.comparator.NodeDistanceComparator) IsPointOnLineEdgeFilter(com.revolsys.geometry.graph.filter.IsPointOnLineEdgeFilter) BoundingBox(com.revolsys.geometry.model.BoundingBox)

Example 2 with NodeDistanceComparator

use of com.revolsys.geometry.graph.comparator.NodeDistanceComparator 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

NodeDistanceComparator (com.revolsys.geometry.graph.comparator.NodeDistanceComparator)2 Edge (com.revolsys.geometry.graph.Edge)1 Node (com.revolsys.geometry.graph.Node)1 IsPointOnLineEdgeFilter (com.revolsys.geometry.graph.filter.IsPointOnLineEdgeFilter)1 NodeCoordinatesFilter (com.revolsys.geometry.graph.filter.NodeCoordinatesFilter)1 BoundingBox (com.revolsys.geometry.model.BoundingBox)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