Package com.graphhopper.reader.osm
Class OSMReader
java.lang.Object
com.graphhopper.reader.osm.OSMReader
Parses an OSM file (xml, zipped xml or pbf) and creates a graph from it. The OSM file is actually read twice.
During the first scan we determine the 'type' of each node, i.e. we check whether a node only appears in a single way
or represents an intersection of multiple ways, or connects two ways. We also scan the relations and store them for
each way ID in memory.
During the second scan we store the coordinates of the nodes that belong to ways in memory and then split each way
into several segments that are divided by intersections or barrier nodes. Each segment is added as an edge of the
resulting graph. Afterwards we scan the relations again to determine turn restrictions.
-
Constructor Summary
ConstructorsConstructorDescriptionOSMReader
(BaseGraph baseGraph, OSMParsers osmParsers, OSMReaderConfig config) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
This method is called for each way during the first and second pass of theWaySegmentParser
.protected void
addEdge
(int fromIndex, int toIndex, PointList pointList, ReaderWay way, List<Map<String, Object>> nodeTags) This method is called for each segment an OSM way is split into during the second pass ofWaySegmentParser
.com.carrotsearch.hppc.IntIntMap
protected boolean
isBarrierNode
(ReaderNode node) protected boolean
protected void
preprocessRelations
(ReaderRelation relation) This method is called for each relation during the first pass ofWaySegmentParser
protected void
preprocessWay
(ReaderWay way, WaySegmentParser.CoordinateSupplier coordinateSupplier, WaySegmentParser.NodeTagSupplier nodeTagSupplier) This method is called for each way during the second pass and before the way is split into edges.protected void
processRelation
(ReaderRelation relation, LongToIntFunction getIdForOSMNodeId) This method is called for each relation during the second pass ofWaySegmentParser
We use it to save the relations and process them afterwards.void
setAreaIndex
(AreaIndex<CustomArea> areaIndex) The area index is queried for each OSM way and the associated areas are added to the way's tagsprotected void
setArtificialWayTags
(PointList pointList, ReaderWay way, double distance, List<Map<String, Object>> nodeTags) This method is called during the second pass ofWaySegmentParser
and provides an entry point to enrich the given OSM way with additional tags before it is passed on to the tag parsers.setCountryRuleFactory
(CountryRuleFactory countryRuleFactory) setElevationProvider
(ElevationProvider eleProvider) Sets the OSM file to be read.toString()
-
Constructor Details
-
OSMReader
-
-
Method Details
-
setFile
Sets the OSM file to be read. Supported formats include .osm.xml, .osm.gz and .xml.pbf -
setAreaIndex
The area index is queried for each OSM way and the associated areas are added to the way's tags -
setElevationProvider
-
setCountryRuleFactory
-
readGraph
- Throws:
IOException
-
getDataDate
- Returns:
- the timestamp given in the OSM file header or null if not found
-
acceptWay
This method is called for each way during the first and second pass of theWaySegmentParser
. All OSM ways that are not accepted here and all nodes that are not referenced by any such way will be ignored. -
isBarrierNode
- Returns:
- true if the given node should be duplicated to create an artificial edge. If the node turns out to be a junction between different ways this will be ignored and no artificial edge will be created.
-
isCalculateWayDistance
- Returns:
- true if the length of the way shall be calculated and added as an artificial way tag
-
setArtificialWayTags
protected void setArtificialWayTags(PointList pointList, ReaderWay way, double distance, List<Map<String, Object>> nodeTags) This method is called during the second pass ofWaySegmentParser
and provides an entry point to enrich the given OSM way with additional tags before it is passed on to the tag parsers. -
addEdge
protected void addEdge(int fromIndex, int toIndex, PointList pointList, ReaderWay way, List<Map<String, Object>> nodeTags) This method is called for each segment an OSM way is split into during the second pass ofWaySegmentParser
.- Parameters:
fromIndex
- a unique integer id for the first node of this segmenttoIndex
- a unique integer id for the last node of this segmentpointList
- coordinates of this segmentway
- the OSM way this segment was taken fromnodeTags
- node tags of this segment. there is one map of tags for each point.
-
preprocessWay
protected void preprocessWay(ReaderWay way, WaySegmentParser.CoordinateSupplier coordinateSupplier, WaySegmentParser.NodeTagSupplier nodeTagSupplier) This method is called for each way during the second pass and before the way is split into edges. We currently use it to parse road names and calculate the distance of a way to determine the speed based on the duration tag when it is present. The latter cannot be done on a per-edge basis, because the duration tag refers to the duration of the entire way. -
preprocessRelations
This method is called for each relation during the first pass ofWaySegmentParser
-
processRelation
This method is called for each relation during the second pass ofWaySegmentParser
We use it to save the relations and process them afterwards. -
getArtificialEdgesByEdges
public com.carrotsearch.hppc.IntIntMap getArtificialEdgesByEdges() -
toString
-