Class PlanitGraphGeoUtils


  • public class PlanitGraphGeoUtils
    extends Object
    A class with utility methods that levarage the geospatial information of planit enities pertaining to graphs. For geo utilities only utilising JTS entities, we refer the user to PlanitJtsUtils instead. this class is dedicated to functionality that directly requires the involvement of Planit Graph elements (vertices, edges, etc.).
    Author:
    markr
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T extends EdgeSegment>
      org.locationtech.jts.geom.LineSegment
      extractClosestLineSegmentTo​(org.locationtech.jts.geom.Geometry referenceGeometry, T edgeSegment, PlanitJtsCrsUtils geoUtils)
      Extract the JTS line segment from the edge segment that is closest to the reference geometry in its intended direction.
      static Edge findEdgeClosest​(org.locationtech.jts.geom.Geometry geometry, Collection<? extends Edge> edges, PlanitJtsCrsUtils geoUtils)
      Find the edge closest to the passed in geometry using a projection from any existing coordinate on the geometry to the geometry of the link.
      static Edge findEdgeClosestToLineString​(org.locationtech.jts.geom.LineString lineString, Collection<? extends Edge> edges, PlanitJtsCrsUtils geoUtils)
      Find the edge closest to the passed in line string using a projection from any existing coordinate on the line string to the geometry of the link.
      static Edge findEdgeClosestToPoint​(org.locationtech.jts.geom.Point point, Collection<? extends Edge> edges, PlanitJtsCrsUtils geoUtils)
      Find the edge closest to the passed in point using a projection from any existing coordinate on the geometry to the geometry of the link.
      static Pair<? extends Edge,​Set<? extends Edge>> findEdgesClosest​(org.locationtech.jts.geom.Geometry geometry, Collection<? extends Edge> edges, double marginToClosestMeters, PlanitJtsCrsUtils geoUtils)
      Find the edge closest to the passed in geometry as well as all other edges within the provided marging using a projection from any existing coordinate on the geometry to the geometry of the link.
      static Pair<? extends Edge,​Set<? extends Edge>> findEdgesClosestToGeometry​(org.locationtech.jts.geom.Geometry geometry, Collection<? extends Edge> edges, double bufferDistanceMeters, PlanitJtsCrsUtils geoUtils)
      Find the edge closest to the passed in geometry as well as all other edges within the given margin using a projection from any existing coordinate on the geometry to the geometry of the link.
      static Pair<? extends Edge,​Set<? extends Edge>> findEdgesClosestToLineString​(org.locationtech.jts.geom.LineString lineString, Collection<? extends Edge> edges, double bufferDistanceMeters, PlanitJtsCrsUtils geoUtils)
      Find the edge closest to the passed in line string using a projection from any existing coordinate on the line string to the geometry of the link.
      static Pair<? extends Edge,​Set<? extends Edge>> findEdgesClosestToPoint​(org.locationtech.jts.geom.Point point, Collection<? extends Edge> edges, double bufferDistanceMeters, PlanitJtsCrsUtils geoUtils)
      Find the edge closest to the passed in point as well as all other edges within the given margin using a projection from any existing coordinate on the geometry to the geometry of the link.
      static <T extends Edge>
      Map<T,​Double>
      findEdgesWithinClosestDistanceDeltaToGeometry​(org.locationtech.jts.geom.Geometry geometry, Collection<T> edges, double bufferDistanceMeters, PlanitJtsCrsUtils geoUtils)
      Find the edges within the given buffer distance (around shortest distance found) to the passed in geometry using a projection from any existing coordinate on the geometry to the geometry of the link.
      protected static <T> Pair<T,​Double> findMinimumValuePair​(Map<? extends T,​Double> valueMap)
      Find the minimum value pair from this map
      protected static <T> Map<T,​Double> findPlanitEntitiesDistance​(org.locationtech.jts.geom.Coordinate reference, Collection<? extends T> planitEntities, PlanitJtsCrsUtils geoUtils)
      Find the distances to the reference point and the geometry for all given PLANit entities with a supported geometry from the provided collection.
      protected static <T> Map<T,​Double> findPlanitEntitiesDistance​(org.locationtech.jts.geom.LineString lineString, Collection<? extends T> planitEntities, PlanitJtsCrsUtils geoUtils)
      Find the distances to the line string and the geometry for all given PLANit entities with a supported geometry from the provided collection.
      protected static <T> Set<? extends T> findPlanitEntitiesWithinDistance​(org.locationtech.jts.geom.Coordinate reference, Collection<? extends T> planitEntities, Double maxDistanceMeters, PlanitJtsCrsUtils geoUtils)
      Find all PLANit entities within striking distance of the line string from the available entities based on the max distance provided.
      protected static <T> Set<? extends T> findPlanitEntitiesWithinDistance​(org.locationtech.jts.geom.LineString lineString, Collection<? extends T> planitEntities, Double maxDistanceMeters, PlanitJtsCrsUtils geoUtils)
      Find all PLANit entities within striking distance of the line string from the available entities based on the max distance provided.
      protected static <T> Pair<T,​Double> findPlanitEntityClosest​(org.locationtech.jts.geom.Coordinate reference, Collection<? extends T> planitEntities, double maxDistanceMeters, PlanitJtsCrsUtils geoUtils)
      Find the closest distance to the reference point and the geometry for some PLANit entity with a supported geometry from the provided collection.
      protected static <T> Pair<T,​Double> findPlanitEntityClosest​(org.locationtech.jts.geom.LineString lineString, Collection<? extends T> planitEntities, double maxDistanceMeters, PlanitJtsCrsUtils geoUtils)
      Find the closest PLANit entity to the line string from the available entities.
      protected static <T> Double findPlanitEntityDistance​(org.locationtech.jts.geom.Coordinate reference, T planitEntity, PlanitJtsCrsUtils geoUtils)
      Find the closest distance to the reference point and the geometry for some PLANit entity with a supported geometry from the provided collection.
      static boolean isVertexNearBoundingBox​(Vertex node, org.locationtech.jts.geom.Envelope boundingBox, double maxDistanceMeters, PlanitJtsCrsUtils geoUtils)
      Verify if node is within maximum distance of provided bounding box
      protected static <T> void removePlanitEntitiesBeyondValue​(Map<? extends T,​Double> entitiesToFilter, Double maxValue)
      Remove all entities that fall outside provided maxDistance
    • Constructor Detail

      • PlanitGraphGeoUtils

        public PlanitGraphGeoUtils()
    • Method Detail

      • findMinimumValuePair

        protected static <T> Pair<T,​Double> findMinimumValuePair​(Map<? extends T,​Double> valueMap)
        Find the minimum value pair from this map
        Type Parameters:
        T - PLANit entity type
        Parameters:
        valueMap - to check
        Returns:
        minimum value pair
      • removePlanitEntitiesBeyondValue

        protected static <T> void removePlanitEntitiesBeyondValue​(Map<? extends T,​Double> entitiesToFilter,
                                                                  Double maxValue)
        Remove all entities that fall outside provided maxDistance
        Type Parameters:
        T - PLANit entity
        Parameters:
        entitiesToFilter - with values , this map is filtered
        maxValue - to filter on
      • findPlanitEntityDistance

        protected static <T> Double findPlanitEntityDistance​(org.locationtech.jts.geom.Coordinate reference,
                                                             T planitEntity,
                                                             PlanitJtsCrsUtils geoUtils)
        Find the closest distance to the reference point and the geometry for some PLANit entity with a supported geometry from the provided collection. This method computes the distance between any location on any line segment of the (outer) boundary of the PLANit entities geometry (or its point location if no polygon/linestring is available) and the reference coordinate and it is therefore very precise. A cap is placed on how far an entity is allowed to be to still be regarded as closest via maxDistanceMeters.
        Type Parameters:
        T - PLANit entity type
        Parameters:
        reference - reference location to find distance to
        planitEntity - to check against using their geometries
        geoUtils - to compute projected distances
        Returns:
        planitEntity closest and distance in meters, null if none matches criteria
      • findPlanitEntitiesDistance

        protected static <T> Map<T,​Double> findPlanitEntitiesDistance​(org.locationtech.jts.geom.Coordinate reference,
                                                                            Collection<? extends T> planitEntities,
                                                                            PlanitJtsCrsUtils geoUtils)
        Find the distances to the reference point and the geometry for all given PLANit entities with a supported geometry from the provided collection. This method computes the distance between any location on any line segment of the (outer) boundary of the PLANit entities geometry (or its point location if no polygon/linestring is available) and the reference coordinate and it is therefore very precise.
        Type Parameters:
        T - PLANit entity type
        Parameters:
        reference - reference location to find distance to
        planitEntities - to check against using their geometries
        geoUtils - to compute projected distances
        Returns:
        planitEntity closest and distance in meters, null if none matches criteria
      • findPlanitEntitiesDistance

        protected static <T> Map<T,​Double> findPlanitEntitiesDistance​(org.locationtech.jts.geom.LineString lineString,
                                                                            Collection<? extends T> planitEntities,
                                                                            PlanitJtsCrsUtils geoUtils)
        Find the distances to the line string and the geometry for all given PLANit entities with a supported geometry from the provided collection. This method computes the distance between any location on any line segment of the (outer) boundary of the PLANit entities geometry (or its point location if no polygon/linestring is available) and the reference coordinate and it is therefore very precise.
        Type Parameters:
        T - PLANit entity type
        Parameters:
        lineString - reference to find distance to
        planitEntities - to check against using their geometries
        geoUtils - to compute projected distances
        Returns:
        planitEntity closest and distance in meters, null if none matches criteria
      • findPlanitEntitiesWithinDistance

        protected static <T> Set<? extends T> findPlanitEntitiesWithinDistance​(org.locationtech.jts.geom.LineString lineString,
                                                                               Collection<? extends T> planitEntities,
                                                                               Double maxDistanceMeters,
                                                                               PlanitJtsCrsUtils geoUtils)
                                                                        throws PlanItException
        Find all PLANit entities within striking distance of the line string from the available entities based on the max distance provided. This method computes the actual distance between any location on any line segment of the geometry of the entity and any existing coordinate on the line string and it is therefore is very precise. A cap is placed on how far an entities geometry is allowed to be away to still be regarded as closest via maxDistanceMeters.
        Type Parameters:
        T - PLANit entity type
        Parameters:
        lineString - reference line string
        planitEntities - to check against using their geometries
        maxDistanceMeters - maximum allowedDistance to be eligible
        geoUtils - to compute projected distances
        Returns:
        closest and its distance, null if none matches criteria
        Throws:
        PlanItException - thrown if error
      • findPlanitEntitiesWithinDistance

        protected static <T> Set<? extends T> findPlanitEntitiesWithinDistance​(org.locationtech.jts.geom.Coordinate reference,
                                                                               Collection<? extends T> planitEntities,
                                                                               Double maxDistanceMeters,
                                                                               PlanitJtsCrsUtils geoUtils)
                                                                        throws PlanItException
        Find all PLANit entities within striking distance of the line string from the available entities based on the max distance provided. This method computes the actual distance between any location on any line segment of the geometry of the entity and any existing coordinate on the line string and it is therefore is very precise. A cap is placed on how far an entities geometry is allowed to be away to still be regarded as closest via maxDistanceMeters.
        Type Parameters:
        T - PLANit entity type
        Parameters:
        reference - reference location to use
        planitEntities - to check against using their geometries
        maxDistanceMeters - maximum allowedDistance to be eligible
        geoUtils - to compute projected distances
        Returns:
        closest and its distance, null if none matches criteria
        Throws:
        PlanItException - thrown if error
      • findPlanitEntityClosest

        protected static <T> Pair<T,​Double> findPlanitEntityClosest​(org.locationtech.jts.geom.Coordinate reference,
                                                                          Collection<? extends T> planitEntities,
                                                                          double maxDistanceMeters,
                                                                          PlanitJtsCrsUtils geoUtils)
                                                                   throws PlanItException
        Find the closest distance to the reference point and the geometry for some PLANit entity with a supported geometry from the provided collection. This method computes the distance between any location on any line segment of the (outer) boundary of the PLANit entities geometry (or its point location if no polygon/linestring is available) and the reference coordinate and it is therefore very precise. A cap is placed on how far an entity is allowed to be to still be regarded as closest via maxDistanceMeters.
        Type Parameters:
        T - PLANit entity type
        Parameters:
        reference - reference location to find distance to
        planitEntities - to check against using their geometries
        maxDistanceMeters - maximum allowedDistance to be eligible
        geoUtils - to compute projected distances
        Returns:
        planitEntity closest and distance in meters, null if none matches criteria
        Throws:
        PlanItException - thrown if error
      • findPlanitEntityClosest

        protected static <T> Pair<T,​Double> findPlanitEntityClosest​(org.locationtech.jts.geom.LineString lineString,
                                                                          Collection<? extends T> planitEntities,
                                                                          double maxDistanceMeters,
                                                                          PlanitJtsCrsUtils geoUtils)
                                                                   throws PlanItException
        Find the closest PLANit entity to the line string from the available entities. This method computes the actual distance between any location on any line segment of the geometry of the entity and any existing coordinate on the line string and it is therefore is very precise. A cap is placed on how far an entities geometry is allowed to be away to still be regarded as closest via maxDistanceMeters.
        Type Parameters:
        T - PLANit entity type
        Parameters:
        lineString - reference line string
        planitEntities - to check against using their geometries
        maxDistanceMeters - maximum allowedDistance to be eligible
        geoUtils - to compute projected distances
        Returns:
        closest and its distance, null if none matches criteria
        Throws:
        PlanItException - thrown if error
      • findEdgeClosest

        public static Edge findEdgeClosest​(org.locationtech.jts.geom.Geometry geometry,
                                           Collection<? extends Edge> edges,
                                           PlanitJtsCrsUtils geoUtils)
        Find the edge closest to the passed in geometry using a projection from any existing coordinate on the geometry to the geometry of the link.
        Parameters:
        geometry - to find closest link for
        edges - to check against
        geoUtils - used to compute distances
        Returns:
        closest edge found
      • findEdgesClosest

        public static Pair<? extends Edge,​Set<? extends Edge>> findEdgesClosest​(org.locationtech.jts.geom.Geometry geometry,
                                                                                      Collection<? extends Edge> edges,
                                                                                      double marginToClosestMeters,
                                                                                      PlanitJtsCrsUtils geoUtils)
        Find the edge closest to the passed in geometry as well as all other edges within the provided marging using a projection from any existing coordinate on the geometry to the geometry of the link.
        Parameters:
        geometry - to find closest link for
        edges - to check against
        marginToClosestMeters - margin used to collect all edges within this margin from the closest edge
        geoUtils - used to compute distances
        Returns:
        closest edge found and the edges within the given margin, null if none
      • findEdgeClosestToLineString

        public static Edge findEdgeClosestToLineString​(org.locationtech.jts.geom.LineString lineString,
                                                       Collection<? extends Edge> edges,
                                                       PlanitJtsCrsUtils geoUtils)
                                                throws PlanItException
        Find the edge closest to the passed in line string using a projection from any existing coordinate on the line string to the geometry of the link.
        Parameters:
        lineString - to find closest link for
        edges - to check against
        geoUtils - used to compute distances
        Returns:
        closest edge found
        Throws:
        PlanItException - thrown if error
      • findEdgeClosestToPoint

        public static Edge findEdgeClosestToPoint​(org.locationtech.jts.geom.Point point,
                                                  Collection<? extends Edge> edges,
                                                  PlanitJtsCrsUtils geoUtils)
                                           throws PlanItException
        Find the edge closest to the passed in point using a projection from any existing coordinate on the geometry to the geometry of the link.
        Parameters:
        point - to find closest link for
        edges - to check against
        geoUtils - used to compute distances
        Returns:
        closest edge found
        Throws:
        PlanItException - thrown if error
      • findEdgesClosestToLineString

        public static Pair<? extends Edge,​Set<? extends Edge>> findEdgesClosestToLineString​(org.locationtech.jts.geom.LineString lineString,
                                                                                                  Collection<? extends Edge> edges,
                                                                                                  double bufferDistanceMeters,
                                                                                                  PlanitJtsCrsUtils geoUtils)
        Find the edge closest to the passed in line string using a projection from any existing coordinate on the line string to the geometry of the link. All edges that are found within a small buffer distance of the closest distance are also retrieved
        Parameters:
        lineString - to find closest link for
        edges - to check against
        bufferDistanceMeters - margin used to collect all edges with distance smaller or equal to buffer (distance to closest edge + this margin)
        geoUtils - used to compute distances
        Returns:
        closest edge found and edges within margin
      • findEdgesClosestToPoint

        public static Pair<? extends Edge,​Set<? extends Edge>> findEdgesClosestToPoint​(org.locationtech.jts.geom.Point point,
                                                                                             Collection<? extends Edge> edges,
                                                                                             double bufferDistanceMeters,
                                                                                             PlanitJtsCrsUtils geoUtils)
        Find the edge closest to the passed in point as well as all other edges within the given margin using a projection from any existing coordinate on the geometry to the geometry of the link. All edges that are found within a small buffer distance of the closest distance are also retrieved
        Parameters:
        point - to find closest link for
        edges - to check against
        bufferDistanceMeters - margin used to collect all edges with distance smaller or equal to buffer (distance to closest edge + this margin)
        geoUtils - used to compute distances
        Returns:
        closest edge found and all other edges within the given margin
      • findEdgesWithinClosestDistanceDeltaToGeometry

        public static <T extends EdgeMap<T,​Double> findEdgesWithinClosestDistanceDeltaToGeometry​(org.locationtech.jts.geom.Geometry geometry,
                                                                                                         Collection<T> edges,
                                                                                                         double bufferDistanceMeters,
                                                                                                         PlanitJtsCrsUtils geoUtils)
        Find the edges within the given buffer distance (around shortest distance found) to the passed in geometry using a projection from any existing coordinate on the geometry to the geometry of the link. All edges that are found within a small buffer distance of the closest distance are also retrieved
        Type Parameters:
        T - type of edge
        Parameters:
        geometry - to find closest link for
        edges - to check against
        bufferDistanceMeters - margin used to collect all edges with distance smaller or equal to buffer (distance to closest edge + this margin)
        geoUtils - used to compute distances
        Returns:
        edges found with their distances to the geometry, can be null if none match
      • findEdgesClosestToGeometry

        public static Pair<? extends Edge,​Set<? extends Edge>> findEdgesClosestToGeometry​(org.locationtech.jts.geom.Geometry geometry,
                                                                                                Collection<? extends Edge> edges,
                                                                                                double bufferDistanceMeters,
                                                                                                PlanitJtsCrsUtils geoUtils)
        Find the edge closest to the passed in geometry as well as all other edges within the given margin using a projection from any existing coordinate on the geometry to the geometry of the link. All edges that are found within a small buffer distance of the closest distance are also retrieved
        Parameters:
        geometry - to find closest link for
        edges - to check against
        bufferDistanceMeters - margin used to collect all edges with distance smaller or equal to buffer (distance to closest edge + this margin)
        geoUtils - used to compute distances
        Returns:
        closest edge found and all other edges within the given margin
      • extractClosestLineSegmentTo

        public static <T extends EdgeSegment> org.locationtech.jts.geom.LineSegment extractClosestLineSegmentTo​(org.locationtech.jts.geom.Geometry referenceGeometry,
                                                                                                                T edgeSegment,
                                                                                                                PlanitJtsCrsUtils geoUtils)
        Extract the JTS line segment from the edge segment that is closest to the reference geometry in its intended direction.
        Type Parameters:
        T - edge segment type
        Parameters:
        referenceGeometry - to determine closeness criteria on
        edgeSegment - to extract line segment from
        geoUtils - for distance calculations
        Returns:
        line segment if found
      • isVertexNearBoundingBox

        public static boolean isVertexNearBoundingBox​(Vertex node,
                                                      org.locationtech.jts.geom.Envelope boundingBox,
                                                      double maxDistanceMeters,
                                                      PlanitJtsCrsUtils geoUtils)
                                               throws PlanItException
        Verify if node is within maximum distance of provided bounding box
        Parameters:
        node - the node
        boundingBox - the bounding box
        maxDistanceMeters - maximum distance between node and bounding box
        geoUtils - to use
        Returns:
        true when within given distance, false otherwise
        Throws:
        PlanItException - thrown if error