Package org.goplanit.osm.util
Class OsmNodeUtils
- java.lang.Object
-
- org.goplanit.osm.util.OsmNodeUtils
-
public class OsmNodeUtils extends Object
Utilities in relation to parsing OSM nodes while constructing a PLANit model from it- Author:
- markr
-
-
Constructor Summary
Constructors Constructor Description OsmNodeUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.locationtech.jts.geom.Coordinate
createCoordinate(de.topobyte.osm4j.core.model.iface.OsmNode osmNode)
Collect the coordinate from the osm node informationstatic org.locationtech.jts.geom.Point
createPoint(long osmNodeId, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Create a point based on the OSMnodestatic org.locationtech.jts.geom.Point
createPoint(de.topobyte.osm4j.core.model.iface.OsmNode osmNode)
Create a point from the nodestatic org.locationtech.jts.geom.Coordinate
findClosestProjectedCoordinateTo(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, org.locationtech.jts.geom.LineString geometry, PlanitJtsCrsUtils geoUtils)
Create a coordinate at the location that represents the closest point between the osmNode and the passed in geometrystatic Edge
findEdgeClosest(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, Collection<? extends Edge> edges, double maxDistanceMeters, PlanitJtsCrsUtils geoUtils)
Find the closest edge to the node location.static Edge
findEdgeClosest(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, Collection<? extends Edge> edges, PlanitJtsCrsUtils geoUtils)
Find the closest link to the node location.static de.topobyte.osm4j.core.model.iface.OsmNode
findOsmNodeWithCoordinate2D(org.locationtech.jts.geom.Coordinate coordinate, Collection<de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
find (first) node who's location coincides with the provided coordinate from the collection of eligible nodes passed instatic Zone
findZoneClosest(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, Collection<? extends Zone> zones, double maxDistanceMeters, PlanitJtsCrsUtils geoUtils)
find the closest zone to the node location.static Zone
findZoneClosest(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, Collection<? extends Zone> zones, PlanitJtsCrsUtils geoUtils)
find the closest zone to the node location.static Zone
findZoneWithClosestCoordinateToNode(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, Collection<? extends Zone> zones, double maxDistanceMeters, PlanitJtsCrsUtils geoUtils)
find the closest zone to the node location.static Zone
findZoneWithClosestCoordinateToNode(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, Collection<? extends Zone> zones, PlanitJtsCrsUtils geoUtils)
identical to findZoneWithClosest coordinate that requires a maximum search distance.static double
getDistanceToZone(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, Zone zone, PlanitJtsCrsUtils geoUtils)
find the distance from the zone to the node.static double
getX(de.topobyte.osm4j.core.model.iface.OsmNode osmNode)
collect x coordinate based on mapping between long/lat/ x/ystatic double
getY(de.topobyte.osm4j.core.model.iface.OsmNode osmNode)
collect x coordinate based on mapping between long/lat/ x/ystatic boolean
nodeLocationEquals2D(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, org.locationtech.jts.geom.Coordinate coordinate)
Verify if the location of the provided coordinate equals the node's location
-
-
-
Method Detail
-
getDistanceToZone
public static double getDistanceToZone(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, Zone zone, PlanitJtsCrsUtils geoUtils) throws PlanItException
find the distance from the zone to the node. This method computes the actual distance between any location on any line segment of the outer boundary of the zones (or its centroid if no polygon/linestring is available) and the reference point and it is therefore very precise.- Parameters:
osmNode
- usedzone
- to check against using its geometrygeoUtils
- to compute projected distances- Returns:
- distance to zone, if not possible to compute positive infinity is returned
- Throws:
PlanItException
- thrown if error
-
createCoordinate
public static org.locationtech.jts.geom.Coordinate createCoordinate(de.topobyte.osm4j.core.model.iface.OsmNode osmNode)
Collect the coordinate from the osm node information- Parameters:
osmNode
- to use- Returns:
- created coordinate
-
createPoint
public static org.locationtech.jts.geom.Point createPoint(de.topobyte.osm4j.core.model.iface.OsmNode osmNode)
Create a point from the node- Parameters:
osmNode
- to create point for- Returns:
- point created
-
createPoint
public static org.locationtech.jts.geom.Point createPoint(long osmNodeId, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes) throws PlanItException
Create a point based on the OSMnode- Parameters:
osmNodeId
- to create point forosmNodes
- to collect node from- Returns:
- created node, or null of osmNodeId is unknown is passed in osmNodes
- Throws:
PlanItException
- thrown if error
-
getX
public static double getX(de.topobyte.osm4j.core.model.iface.OsmNode osmNode)
collect x coordinate based on mapping between long/lat/ x/y- Parameters:
osmNode
- node to collect from- Returns:
- x coordinate
-
getY
public static double getY(de.topobyte.osm4j.core.model.iface.OsmNode osmNode)
collect x coordinate based on mapping between long/lat/ x/y- Parameters:
osmNode
- node to collect from- Returns:
- x coordinate
-
findZoneWithClosestCoordinateToNode
public static Zone findZoneWithClosestCoordinateToNode(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, Collection<? extends Zone> zones, PlanitJtsCrsUtils geoUtils) throws PlanItException
identical to findZoneWithClosest coordinate that requires a maximum search distance. Here this distance is set to inifinite- Parameters:
osmNode
- referencezones
- to check againstgeoUtils
- to compute distance- Returns:
- zone with the geometry coordinate (or centroid) closest to the osmNode
- Throws:
PlanItException
- thrown if error
-
findZoneWithClosestCoordinateToNode
public static Zone findZoneWithClosestCoordinateToNode(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, Collection<? extends Zone> zones, double maxDistanceMeters, PlanitJtsCrsUtils geoUtils) throws PlanItException
find the closest zone to the node location. Note that this method is NOT perfect, it utilises the closest coordinate on the geometry of the zone, but it is likely the closest point lies on a line of the geometry rather than an extreme point. Therefore it is possible that the found zone is not actually closest. So use with caution!- Parameters:
osmNode
- referencezones
- to check againstgeoUtils
- to compute distancemaxDistanceMeters
- maximum allowable distance to search for- Returns:
- zone with the geometry coordinate (or centroid) closest to the osmNode
- Throws:
PlanItException
- thrown if error
-
findZoneClosest
public static Zone findZoneClosest(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, Collection<? extends Zone> zones, PlanitJtsCrsUtils geoUtils) throws PlanItException
find the closest zone to the node location. This method computes the actual distance between any location on any line segment of the outer boundary of the zones (or its centroid if no polygon/linestring is available) and the reference point and it therefore very precise- Parameters:
osmNode
- reference nodezones
- to check against using their geometriesgeoUtils
- to compute projected distances- Returns:
- zone closest, null if none matches criteria
- Throws:
PlanItException
- thrown if error
-
findZoneClosest
public static Zone findZoneClosest(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, Collection<? extends Zone> zones, double maxDistanceMeters, PlanitJtsCrsUtils geoUtils) throws PlanItException
find the closest zone to the node location. This method computes the actual distance between any location on any line segment of the outer boundary of the zones (or its centroid if no polygon/linestring is available) and the reference point and it is therefore very precise. A cap is placed on how far a zone is allowed to be to still be regarded as closest via maxDistanceMeters.- Parameters:
osmNode
- reference nodezones
- to check against using their geometriesmaxDistanceMeters
- maximum allowedDistance to be eligiblegeoUtils
- to compute projected distances- Returns:
- zone closest, null if none matches criteria
- Throws:
PlanItException
- thrown if error
-
findClosestProjectedCoordinateTo
public static org.locationtech.jts.geom.Coordinate findClosestProjectedCoordinateTo(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, org.locationtech.jts.geom.LineString geometry, PlanitJtsCrsUtils geoUtils) throws PlanItException
Create a coordinate at the location that represents the closest point between the osmNode and the passed in geometry- Parameters:
osmNode
- reference nodegeometry
- geometry to find closest location to node ongeoUtils
- used for computing the distances- Returns:
- projected coordinate
- Throws:
PlanItException
- thrown if error
-
findEdgeClosest
public static Edge findEdgeClosest(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, Collection<? extends Edge> edges, PlanitJtsCrsUtils geoUtils) throws PlanItException
Find the closest link to the node location. This method computes the actual distance between any location on any line segment of the geometry of the link and the reference point (OSM node) and it is therefore very precise.- Parameters:
osmNode
- reference nodeedges
- to check against using their geometriesgeoUtils
- to compute projected distances- Returns:
- edge closest, null if none matches criteria
- Throws:
PlanItException
- thrown if error
-
findEdgeClosest
public static Edge findEdgeClosest(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, Collection<? extends Edge> edges, double maxDistanceMeters, PlanitJtsCrsUtils geoUtils) throws PlanItException
Find the closest edge to the node location. This method computes the actual distance between any location on any line segment of geometry of the link and the reference point (OSM node) and it therefore very precise. A cap is placed on how far a zone is allowed to be to still be regarded as closest via maxDistanceMeters.- Parameters:
osmNode
- reference nodeedges
- to check against using their geometriesmaxDistanceMeters
- maximum allowedDistance to be eligiblegeoUtils
- to compute projected distances- Returns:
- edge closest, null if none matches criteria
- Throws:
PlanItException
- thrown if error
-
findOsmNodeWithCoordinate2D
public static de.topobyte.osm4j.core.model.iface.OsmNode findOsmNodeWithCoordinate2D(org.locationtech.jts.geom.Coordinate coordinate, Collection<de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
find (first) node who's location coincides with the provided coordinate from the collection of eligible nodes passed in- Parameters:
coordinate
- to matchosmNodes
- to match against- Returns:
- found node that matches, null if no match found
-
nodeLocationEquals2D
public static boolean nodeLocationEquals2D(de.topobyte.osm4j.core.model.iface.OsmNode osmNode, org.locationtech.jts.geom.Coordinate coordinate)
Verify if the location of the provided coordinate equals the node's location- Parameters:
osmNode
- osmNode to checkcoordinate
- to check against- Returns:
- true when a match, false otherwise
-
-