Package org.goplanit.osm.util
Class OsmWayUtils
- java.lang.Object
-
- org.goplanit.osm.util.OsmWayUtils
-
public class OsmWayUtils extends Object
Utilities in relation to parsing osm ways and constructing a PLANit model from it- Author:
- markr
-
-
Constructor Summary
Constructors Constructor Description OsmWayUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.locationtech.jts.geom.Coordinate[]
createCoordinateArray(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, int startNodeIndex, int endNodeIndex, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Based on the passed in osmWay collect the coordinates on that way as a coordinate array for the given range.static org.locationtech.jts.geom.Coordinate[]
createCoordinateArray(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Based on the passed in osmWay collect the coordinates on that way as a coordinate array.static org.locationtech.jts.geom.Coordinate[]
createCoordinateArray(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, int startNodeIndex, int endNodeIndex, PlanitExceptionConsumer<Set<Long>> missingNodeConsumer)
Based on the passed in osmWay collect the coordinates on that way as a coordinate array.static org.locationtech.jts.geom.Coordinate[]
createCoordinateArrayNoThrow(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, int startNodeIndex, int endNodeIndex, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Based on the passed in osmWay collect the coordinates on that way as a coordinate array for the given range.static org.locationtech.jts.geom.Coordinate[]
createCoordinateArrayNoThrow(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Based on the passed in osmWay collect the coordinates on that way as a coordinate array.static org.locationtech.jts.geom.Geometry
extractGeometry(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
extract geometry from the osm way which can either be a line string or polygonstatic org.locationtech.jts.geom.Geometry
extractGeometry(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, Level logLevel)
extract geometry from the OSM way which can either be a line string or polygonstatic org.locationtech.jts.geom.LineString
extractLineString(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, int startNodeIndex, int endNodeIndex, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Extract the geometry for the passed in way as line string for the given nodesstatic org.locationtech.jts.geom.LineString
extractLineString(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Extract the geometry for the passed in way as line stringstatic org.locationtech.jts.geom.LineString
extractLineStringNoThrow(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, int startNodeIndex, int endNodeIndex, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Identical toextractLineString(de.topobyte.osm4j.core.model.iface.OsmWay, java.util.Map<java.lang.Long, de.topobyte.osm4j.core.model.iface.OsmNode>)
, except it does not throw exceptions, but simply logs any issues foundstatic org.locationtech.jts.geom.LineString
extractLineStringNoThrow(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Identical toextractLineString(de.topobyte.osm4j.core.model.iface.OsmWay, java.util.Map<java.lang.Long, de.topobyte.osm4j.core.model.iface.OsmNode>)
, except it does not throw exceptions, but simply logs any issues foundstatic org.locationtech.jts.geom.Point
extractPoint(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
creates a point geometry using the first available node from the nodes on the OSM way.static org.locationtech.jts.geom.Polygon
extractPolygon(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Extract the geometry for the passed in way as polygon (assumed it has been identified as such already)static org.locationtech.jts.geom.Polygon
extractPolygonNoThrow(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
identical toextractPolygon(OsmWay, Map)
, except it does not throw exceptions, but simply logs any issues found and tries to salvage the polygon by creating it out of the coordinates that are available as lnog as we can still create a closed 2D shape.static Edge
findEdgeClosest(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Collection<? extends Edge> edges, double maxDistanceMeters, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, boolean suppressLogging, PlanitJtsCrsUtils geoUtils)
find the closest edge to the way from the available edges.static Edge
findEdgeClosest(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Collection<? extends Edge> edges, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, boolean suppressLogging, PlanitJtsCrsUtils geoUtils)
find the closest edge to the way from the available edges.static Integer
findFirstAvailableOsmNodeIndexAfter(int offsetIndex, de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
finds the first available osm node index on the osm waystatic Pair<Integer,Integer>
findIndicesOfFirstLoop(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, int initialNodeIndex)
Find the start and end index of the first circular component of the passed in way (if any).static Integer
findLastAvailableOsmNodeIndexAfter(int offsetIndex, de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Finds the last consecutive available OSM node index after the offset, i.e.static org.locationtech.jts.geom.LineSegment
findMinimumLineSegmentBetween(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, org.locationtech.jts.geom.LineString geometry, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, PlanitJtsCrsUtils geoUtils)
find the minimum distance line segment that connects the osmWay to the passed in line string geometrystatic String
findMostProminentOsmHighWayType(Set<? extends Edge> edges)
find the most prominent (important) of the edges based on the osm highway type they carryprotected static <T> T
findPlanitEntityClosest(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Collection<? extends T> planitEntities, double maxDistanceMeters, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, boolean suppressLogging, PlanitJtsCrsUtils geoUtils)
find the closest PLANit entity to the way from the available entities.static String
findWayTypeValueForEligibleKey(Map<String,String> tags)
Verify existence of any of the supported way keys (highway=, railway=, or a waterway one (route=ferry, ferry=_highway_type) and return the valuestatic Zone
findZoneClosest(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Collection<? extends Zone> zones, double maxDistanceMeters, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, boolean suppressLogging, PlanitJtsCrsUtils geoUtils)
Find the closest zone to the way .static Zone
findZoneClosest(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Collection<? extends Zone> zones, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, boolean suppressLogging, PlanitJtsCrsUtils geoUtils)
Find the closest zone to the way .static Integer
getOsmWayNodeIndexByLocation(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, org.locationtech.jts.geom.Point nodePosition, OsmNetworkReaderData networkData)
Collect index by location within the way.static boolean
isAllOsmWayNodesAvailable(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Verify that all OSM nodes in the OSM way are availablestatic boolean
isCircularOsmWay(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<String,String> tags, boolean mustEndAtStart)
Verify if passed osmWay is in fact circular in nature, e.g., , a type of roundabout.static boolean
isCircularWayDefaultDirectionClockwise(String countryName)
The OSM default driving direction on a roundabout is either anticlockwise (right hand drive countries) or clockwise (left hand drive countries), here we verify, based on the country name, if the default is clockwise or not (anticlockwise)static boolean
isCircularWayDirectionClosed(Map<String,String> tags, boolean isForwardDirection, String countryName)
assuming the tags represent an OSM way that is tagged as a junction=roundabout or circular, this method verifies the driving direction on this way based on the country it resides in or an explicit override of the clockwise or anticlockwise direction tags.static boolean
isOsmWayPerfectLoop(de.topobyte.osm4j.core.model.iface.OsmWay osmWay)
Verify if the OSM way is a perfect loop, i.e., its first node equates to the last nodestatic void
removeEdgesWithOsmHighwayTypesLessImportantThan(String osmHighwayType, Set<? extends Edge> edgesToFilter)
Remove all edges with osm way types that are deemed less prominent than the one provided based on the OSM highway tags ordering
-
-
-
Method Detail
-
findPlanitEntityClosest
protected static <T> T findPlanitEntityClosest(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Collection<? extends T> planitEntities, double maxDistanceMeters, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, boolean suppressLogging, PlanitJtsCrsUtils geoUtils)
find the closest PLANit entity to the way 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 node on the way and it is therefore is very precise. A cap is placed on how far a zone is allowed to be to still be regarded as closest via maxDistanceMeters.- Type Parameters:
T
- type of the PLANit entity- Parameters:
osmWay
- reference wayplanitEntities
- to check against using their geometriesmaxDistanceMeters
- maximum allowedDistance to be eligibleosmNodes
- the way might refer tosuppressLogging
- when true suppress logging, false otherwisegeoUtils
- to compute projected distances- Returns:
- closest, null if none matches criteria
-
isCircularOsmWay
public static boolean isCircularOsmWay(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<String,String> tags, boolean mustEndAtStart)
Verify if passed osmWay is in fact circular in nature, e.g., , a type of roundabout. The way must be of type highway or railway as well- Parameters:
osmWay
- the way to verifytags
- of this OSM waymustEndAtStart
- , when true only circular roads where the end node is the start node are identified, when false, any node that appears twice results in a positive result (true is returned)- Returns:
- true if circular, false otherwise
-
isOsmWayPerfectLoop
public static boolean isOsmWayPerfectLoop(de.topobyte.osm4j.core.model.iface.OsmWay osmWay)
Verify if the OSM way is a perfect loop, i.e., its first node equates to the last node- Parameters:
osmWay
- to check- Returns:
- true when circular way, i.e., enclosed area, false otherwise
-
findIndicesOfFirstLoop
public static Pair<Integer,Integer> findIndicesOfFirstLoop(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, int initialNodeIndex)
Find the start and end index of the first circular component of the passed in way (if any).- Parameters:
osmWay
- to checkinitialNodeIndex
- offset to use, when set it uses it as the starting point to start looking- Returns:
- pair of indices demarcating the first two indices with the same node conditional on the offset, null if not found
-
isCircularWayDefaultDirectionClockwise
public static boolean isCircularWayDefaultDirectionClockwise(String countryName)
The OSM default driving direction on a roundabout is either anticlockwise (right hand drive countries) or clockwise (left hand drive countries), here we verify, based on the country name, if the default is clockwise or not (anticlockwise)- Parameters:
countryName
- to check- Returns:
- true when lockwise direction is default, false otherwise
-
isCircularWayDirectionClosed
public static boolean isCircularWayDirectionClosed(Map<String,String> tags, boolean isForwardDirection, String countryName)
assuming the tags represent an OSM way that is tagged as a junction=roundabout or circular, this method verifies the driving direction on this way based on the country it resides in or an explicit override of the clockwise or anticlockwise direction tags. Because OSM implicitly assumes these ways are one way and they comply with country specific direction defaults we must utilise this method to find out what the actual driving direction is- Parameters:
tags
- to useisForwardDirection
- the direction that we want to verify if it is closedcountryName
- country name we determine the driving direction from in case it is not explicitly tagged- Returns:
- true when isForwardDirection is closed, false otherwise
-
createCoordinateArray
public static org.locationtech.jts.geom.Coordinate[] createCoordinateArray(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, int startNodeIndex, int endNodeIndex, PlanitExceptionConsumer<Set<Long>> missingNodeConsumer) throws PlanItException
Based on the passed in osmWay collect the coordinates on that way as a coordinate array. In case something goes wrong and missing nodes are found, the passed in consumer is called to deal with it. User can decide to throw an exception or do something else entirely. If no exception is thrown, the nodes that could be parsed will be returned- Parameters:
osmWay
- to extract node coordinates fromosmNodes
- to collect nodes from by reference node ids in the waystartNodeIndex
- referenceendNodeIndex
- referencemissingNodeConsumer
- callback in case of missing node found- Returns:
- coordinate array found, empty when no nodes were found available
- Throws:
PlanItException
- thrown if error
-
createCoordinateArray
public static org.locationtech.jts.geom.Coordinate[] createCoordinateArray(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes) throws PlanItException
Based on the passed in osmWay collect the coordinates on that way as a coordinate array. In case there are missing nodes or something else goes wrong a PlanitException is thrown- Parameters:
osmWay
- to extract node coordinates fromosmNodes
- to collect nodes from by reference node ids in the way- Returns:
- coordinate array
- Throws:
PlanItException
- thrown if error
-
createCoordinateArray
public static org.locationtech.jts.geom.Coordinate[] createCoordinateArray(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, int startNodeIndex, int endNodeIndex, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes) throws PlanItException
Based on the passed in osmWay collect the coordinates on that way as a coordinate array for the given range. In case there are missing nodes or something else goes wrong a PlanitException is thrown- Parameters:
osmWay
- to extract node coordinates fromosmNodes
- to collect nodes from by reference node ids in the waystartNodeIndex
- to useendNodeIndex
- to use- Returns:
- coordinate array
- Throws:
PlanItException
- thrown if error
-
createCoordinateArrayNoThrow
public static org.locationtech.jts.geom.Coordinate[] createCoordinateArrayNoThrow(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, int startNodeIndex, int endNodeIndex, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes) throws PlanItException
Based on the passed in osmWay collect the coordinates on that way as a coordinate array for the given range. In case there are missing nodes we log this but retain as much of the information in the returned coordinate array as possible- Parameters:
osmWay
- to extract node coordinates fromosmNodes
- to collect nodes from by reference node ids in the waystartNodeIndex
- to useendNodeIndex
- to use- Returns:
- coordinate array
- Throws:
PlanItException
- thrown if error
-
createCoordinateArrayNoThrow
public static org.locationtech.jts.geom.Coordinate[] createCoordinateArrayNoThrow(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Based on the passed in osmWay collect the coordinates on that way as a coordinate array. In case there are missing nodes we log this but retain as much of the information in the returned coordinate array as possible- Parameters:
osmWay
- to extract node coordinates fromosmNodes
- to collect nodes from by reference node ids in the way- Returns:
- coordinate array
-
extractGeometry
public static org.locationtech.jts.geom.Geometry extractGeometry(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes) throws PlanItException
extract geometry from the osm way which can either be a line string or polygon- Parameters:
osmWay
- to extract geometry forosmNodes
- to extract geo features from- Returns:
- created geometry
- Throws:
PlanItException
- thrown if error
-
extractGeometry
public static org.locationtech.jts.geom.Geometry extractGeometry(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, Level logLevel)
extract geometry from the OSM way which can either be a line string or polygon- Parameters:
osmWay
- to extract geometry forosmNodes
- to extract geo features fromlogLevel
- logLevel- Returns:
- created geometry
-
extractLineString
public static org.locationtech.jts.geom.LineString extractLineString(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes) throws PlanItException
Extract the geometry for the passed in way as line string- Parameters:
osmWay
- way to extract geometry fromosmNodes
- to consider- Returns:
- line string instance representing the shape of the way
- Throws:
PlanItException
- thrown if error
-
extractLineString
public static org.locationtech.jts.geom.LineString extractLineString(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, int startNodeIndex, int endNodeIndex, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes) throws PlanItException
Extract the geometry for the passed in way as line string for the given nodes- Parameters:
osmWay
- way to extract geometry fromstartNodeIndex
- to useendNodeIndex
- to useosmNodes
- to consider- Returns:
- line string instance representing the shape of the way
- Throws:
PlanItException
- thrown if error
-
extractLineStringNoThrow
public static org.locationtech.jts.geom.LineString extractLineStringNoThrow(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, int startNodeIndex, int endNodeIndex, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes) throws PlanItException
Identical toextractLineString(de.topobyte.osm4j.core.model.iface.OsmWay, java.util.Map<java.lang.Long, de.topobyte.osm4j.core.model.iface.OsmNode>)
, except it does not throw exceptions, but simply logs any issues found- Parameters:
osmWay
- way to extract geometry fromstartNodeIndex
- to useendNodeIndex
- to useosmNodes
- to consider- Returns:
- line string instance representing the shape of the way
- Throws:
PlanItException
- thrown if error
-
extractLineStringNoThrow
public static org.locationtech.jts.geom.LineString extractLineStringNoThrow(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Identical toextractLineString(de.topobyte.osm4j.core.model.iface.OsmWay, java.util.Map<java.lang.Long, de.topobyte.osm4j.core.model.iface.OsmNode>)
, except it does not throw exceptions, but simply logs any issues found- Parameters:
osmWay
- to extract geometry forosmNodes
- to collect from- Returns:
- parsed geometry, can be null if not valid for some reason
-
extractPoint
public static org.locationtech.jts.geom.Point extractPoint(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
creates a point geometry using the first available node from the nodes on the OSM way. Only to be used when no line string or polygon could be extract due to missing nodes for example- Parameters:
osmWay
- to extract point geometry forosmNodes
- to collect from- Returns:
- parsed geometry, can be null if not valid for some reason
-
extractPolygon
public static org.locationtech.jts.geom.Polygon extractPolygon(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes) throws PlanItException
Extract the geometry for the passed in way as polygon (assumed it has been identified as such already)- Parameters:
osmWay
- to extract geometry forosmNodes
- to collect from- Returns:
- parsed geometry
- Throws:
PlanItException
- thrown if error
-
extractPolygonNoThrow
public static org.locationtech.jts.geom.Polygon extractPolygonNoThrow(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
identical toextractPolygon(OsmWay, Map)
, except it does not throw exceptions, but simply logs any issues found and tries to salvage the polygon by creating it out of the coordinates that are available as lnog as we can still create a closed 2D shape.- Parameters:
osmWay
- to extract geometry forosmNodes
- to collect from- Returns:
- parsed geometry
-
findZoneClosest
public static Zone findZoneClosest(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Collection<? extends Zone> zones, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, boolean suppressLogging, PlanitJtsCrsUtils geoUtils)
Find the closest zone to the way . 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 any node on the way and it is therefore is very precise- Parameters:
osmWay
- reference wayzones
- to check against using their geometriesosmNodes
- to considersuppressLogging
- when true suppress logging, false otherwisegeoUtils
- to compute projected distances- Returns:
- zone closest, null if none matches criteria
-
findZoneClosest
public static Zone findZoneClosest(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Collection<? extends Zone> zones, double maxDistanceMeters, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, boolean suppressLogging, PlanitJtsCrsUtils geoUtils)
Find the closest zone to the way . 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 any node on the way and it is therefore is very precise. A cap is placed on how far a zone is allowed to be to still be regarded as closest via maxDistanceMeters.- Parameters:
osmWay
- reference wayzones
- to check against using their geometriesmaxDistanceMeters
- maximum allowedDistance to be eligibleosmNodes
- the way might refer tosuppressLogging
- when true suppress logging, false otherwisegeoUtils
- to compute projected distances- Returns:
- zone closest, null if none matches criteria
-
findEdgeClosest
public static Edge findEdgeClosest(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Collection<? extends Edge> edges, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, boolean suppressLogging, PlanitJtsCrsUtils geoUtils)
find the closest edge to the way from the available edges. This method computes the actual distance between any location on any line segment of the geometry of the edge and any node on the way and it is therefore is very precise- Parameters:
osmWay
- reference wayedges
- to check against using their geometriesosmNodes
- the way might refer tosuppressLogging
- when true suppress logging, false otherwisegeoUtils
- to compute projected distances- Returns:
- edge closest, null if none matches criteria
-
findEdgeClosest
public static Edge findEdgeClosest(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Collection<? extends Edge> edges, double maxDistanceMeters, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, boolean suppressLogging, PlanitJtsCrsUtils geoUtils)
find the closest edge to the way from the available edges. This method computes the actual distance between any location on any line segment of the geometry of the edge and any node on the way and it is therefore is very precise. A cap is placed on how far a zone is allowed to be to still be regarded as closest via maxDistanceMeters.- Parameters:
osmWay
- reference wayedges
- to check against using their geometriesmaxDistanceMeters
- maximum allowedDistance to be eligibleosmNodes
- the way might refer tosuppressLogging
- when true suppress logging, false otherwisegeoUtils
- to compute projected distances- Returns:
- edge closest, null if none matches criteria
-
findMinimumLineSegmentBetween
public static org.locationtech.jts.geom.LineSegment findMinimumLineSegmentBetween(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, org.locationtech.jts.geom.LineString geometry, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes, PlanitJtsCrsUtils geoUtils)
find the minimum distance line segment that connects the osmWay to the passed in line string geometry- Parameters:
osmWay
- to usegeometry
- to find minimum line segment toosmNodes
- to use for extracting geo information regarding the osm waygeoUtils
- to compute distances- Returns:
- line segment with minimum distance connecting the way and the geometry
-
findMostProminentOsmHighWayType
public static String findMostProminentOsmHighWayType(Set<? extends Edge> edges)
find the most prominent (important) of the edges based on the osm highway type they carry- Parameters:
edges
- to check- Returns:
- osm highway type found to be the most prominent
-
removeEdgesWithOsmHighwayTypesLessImportantThan
public static void removeEdgesWithOsmHighwayTypesLessImportantThan(String osmHighwayType, Set<? extends Edge> edgesToFilter)
Remove all edges with osm way types that are deemed less prominent than the one provided based on the OSM highway tags ordering- Parameters:
osmHighwayType
- to use as a referenceedgesToFilter
- the collection being filtered
-
findFirstAvailableOsmNodeIndexAfter
public static Integer findFirstAvailableOsmNodeIndexAfter(int offsetIndex, de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
finds the first available osm node index on the osm way- Parameters:
offsetIndex
- to start search fromosmWay
- to collect fromosmNodes
- to check existence of osm way nodes- Returns:
- index of first available osm node, null if not found
-
findLastAvailableOsmNodeIndexAfter
public static Integer findLastAvailableOsmNodeIndexAfter(int offsetIndex, de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Finds the last consecutive available OSM node index after the offset, i.e. the index before the first unavailable node- Parameters:
offsetIndex
- to start search fromosmWay
- to collect fromosmNodes
- to check existence of osm way nodes- Returns:
- last index of node that is available, null otherwise
-
isAllOsmWayNodesAvailable
public static boolean isAllOsmWayNodesAvailable(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<Long,de.topobyte.osm4j.core.model.iface.OsmNode> osmNodes)
Verify that all OSM nodes in the OSM way are available- Parameters:
osmWay
- to verifyosmNodes
- to check existence of OSM way nodes- Returns:
- true when complete, false otherwise
-
getOsmWayNodeIndexByLocation
public static Integer getOsmWayNodeIndexByLocation(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, org.locationtech.jts.geom.Point nodePosition, OsmNetworkReaderData networkData)
Collect index by location within the way. first collect node from all nodes and then extract location because if duplicate nodes in the same location exist, collecting by location directly from layer data could yield the wrong node. this way we are certain to extract the location from the right OSM node- Parameters:
osmWay
- way to usenodePosition
- node position to findnetworkData
- to use- Returns:
- the index, null if nothing is found
-
findWayTypeValueForEligibleKey
public static String findWayTypeValueForEligibleKey(Map<String,String> tags)
Verify existence of any of the supported way keys (highway=, railway=, or a waterway one (route=ferry, ferry=_highway_type) and return the value- Parameters:
tags
- to check- Returns:
- value found or log warning
-
-