Package org.goplanit.utils.geo
Class PlanitGraphGeoUtils
- java.lang.Object
-
- org.goplanit.utils.geo.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
-
-
Constructor Summary
Constructors Constructor Description PlanitGraphGeoUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Edge>
org.locationtech.jts.index.quadtree.QuadtreecreateSpatiallyIndexedPlanitEdges(Collection<? extends GraphEntities<T>> edgesCollection)
Created quadtree based on edge envelopes as spatial index.static <T extends EdgeSegment>
org.locationtech.jts.geom.LineSegmentextractClosestLineSegmentTo(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>
Collection<T>findEdgesSpatially(org.locationtech.jts.geom.Envelope searchBoundingBox, org.locationtech.jts.index.quadtree.Quadtree spatiallyIndexedEdgeTree)
Find edges spatially based on the provided bounding box and spatially indexed quadtree containing edges as valuesprotected static <T> Pair<T,Double>
findMinimumValuePair(Map<? extends T,Double> valueMap)
Find the minimum value pair from this mapprotected 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> Map<T,Double>
findPlanitEntitiesDistance(org.locationtech.jts.geom.Point referencePoint, 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> 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> Set<? extends T>
findPlanitEntitiesWithinDistance(org.locationtech.jts.geom.Point referencePoint, 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.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> Pair<T,Double>
findPlanitEntityClosest(org.locationtech.jts.geom.Point referencePoint, 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> Double
findPlanitEntityDistance(org.locationtech.jts.geom.Point referencePoint, 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 boxprotected static <T> void
removePlanitEntitiesBeyondValue(Map<? extends T,Double> entitiesToFilter, Double maxValue)
Remove all entities that fall outside provided maxDistance
-
-
-
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 filteredmaxValue
- to filter on
-
findPlanitEntityDistance
protected static <T> Double findPlanitEntityDistance(org.locationtech.jts.geom.Point referencePoint, T planitEntity, 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:
referencePoint
- reference location to find distance toplanitEntity
- to check against using their geometriesgeoUtils
- to compute projected distances- Returns:
- planitEntity closest and distance in meters, null if none matches criteria
- Throws:
PlanItException
- thrown if error
-
findPlanitEntitiesDistance
protected static <T> Map<T,Double> findPlanitEntitiesDistance(org.locationtech.jts.geom.Point referencePoint, Collection<? extends T> planitEntities, PlanitJtsCrsUtils geoUtils) throws PlanItException
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:
referencePoint
- reference location to find distance toplanitEntities
- to check against using their geometriesgeoUtils
- to compute projected distances- Returns:
- planitEntity closest and distance in meters, null if none matches criteria
- Throws:
PlanItException
- thrown if error
-
findPlanitEntitiesDistance
protected static <T> Map<T,Double> findPlanitEntitiesDistance(org.locationtech.jts.geom.LineString lineString, Collection<? extends T> planitEntities, PlanitJtsCrsUtils geoUtils) throws PlanItException
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 toplanitEntities
- to check against using their geometriesgeoUtils
- to compute projected distances- Returns:
- planitEntity closest and distance in meters, null if none matches criteria
- Throws:
PlanItException
- thrown if error
-
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 stringplanitEntities
- to check against using their geometriesmaxDistanceMeters
- maximum allowedDistance to be eligiblegeoUtils
- 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.Point referencePoint, 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:
referencePoint
- reference point to useplanitEntities
- to check against using their geometriesmaxDistanceMeters
- maximum allowedDistance to be eligiblegeoUtils
- 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.Point referencePoint, 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:
referencePoint
- reference location to find distance toplanitEntities
- to check against using their geometriesmaxDistanceMeters
- maximum allowedDistance to be eligiblegeoUtils
- 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 stringplanitEntities
- to check against using their geometriesmaxDistanceMeters
- maximum allowedDistance to be eligiblegeoUtils
- 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) throws PlanItException
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 foredges
- to check againstgeoUtils
- used to compute distances- Returns:
- closest edge found
- Throws:
PlanItException
- thrown if error
-
findEdgesClosest
public static Pair<? extends Edge,Set<? extends Edge>> findEdgesClosest(org.locationtech.jts.geom.Geometry geometry, Collection<? extends Edge> edges, double marginToClosestMeters, PlanitJtsCrsUtils geoUtils) throws PlanItException
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 foredges
- to check againstmarginToClosestMeters
- margin used to collect all edges within this margin from the closest edgegeoUtils
- used to compute distances- Returns:
- closest edge found and the edges within the given margin, null if none
- Throws:
PlanItException
- thrown if error
-
createSpatiallyIndexedPlanitEdges
public static <T extends Edge> org.locationtech.jts.index.quadtree.Quadtree createSpatiallyIndexedPlanitEdges(Collection<? extends GraphEntities<T>> edgesCollection)
Created quadtree based on edge envelopes as spatial index. Requires PlanitJtsIntersectEdgeVisitor to filter out true spatial matches when querying.- Type Parameters:
T
- type of edge- Parameters:
edgesCollection
- collections to add- Returns:
- created quadtree instance
-
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 foredges
- to check againstgeoUtils
- 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 foredges
- to check againstgeoUtils
- 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) 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. All edges that are found within a small buffer distance of the closest distance are also retrieved- Parameters:
lineString
- to find closest link foredges
- to check againstbufferDistanceMeters
- 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
- Throws:
PlanItException
- thrown if error
-
findEdgesClosestToPoint
public static Pair<? extends Edge,Set<? extends Edge>> findEdgesClosestToPoint(org.locationtech.jts.geom.Point point, Collection<? extends Edge> edges, double bufferDistanceMeters, PlanitJtsCrsUtils geoUtils) throws PlanItException
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 foredges
- to check againstbufferDistanceMeters
- 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
- Throws:
PlanItException
- thrown if error
-
findEdgesClosestToGeometry
public static Pair<? extends Edge,Set<? extends Edge>> findEdgesClosestToGeometry(org.locationtech.jts.geom.Geometry geometry, Collection<? extends Edge> edges, double bufferDistanceMeters, PlanitJtsCrsUtils geoUtils) throws PlanItException
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 foredges
- to check againstbufferDistanceMeters
- 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
- Throws:
PlanItException
- thrown if error
-
findEdgesSpatially
public static <T extends Edge> Collection<T> findEdgesSpatially(org.locationtech.jts.geom.Envelope searchBoundingBox, org.locationtech.jts.index.quadtree.Quadtree spatiallyIndexedEdgeTree)
Find edges spatially based on the provided bounding box and spatially indexed quadtree containing edges as values- Type Parameters:
T
- type of edge- Parameters:
searchBoundingBox
- to usespatiallyIndexedEdgeTree
- to consider- Returns:
- links found intersecting or within bounding box provided
-
extractClosestLineSegmentTo
public static <T extends EdgeSegment> org.locationtech.jts.geom.LineSegment extractClosestLineSegmentTo(org.locationtech.jts.geom.Geometry referenceGeometry, T edgeSegment, PlanitJtsCrsUtils geoUtils) throws PlanItException
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 onedgeSegment
- to extract line segment fromgeoUtils
- for distance calculations- Returns:
- line segment if found
- Throws:
PlanItException
- thrown if error
-
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 nodeboundingBox
- the bounding boxmaxDistanceMeters
- maximum distance between node and bounding boxgeoUtils
- to use- Returns:
- true when within given distance, false otherwise
- Throws:
PlanItException
- thrown if error
-
-