Class OsmNetworkHandler
- java.lang.Object
-
- de.topobyte.osm4j.core.access.DefaultOsmHandler
-
- org.goplanit.osm.converter.network.OsmNetworkHandler
-
- All Implemented Interfaces:
de.topobyte.osm4j.core.access.OsmHandler
public class OsmNetworkHandler extends de.topobyte.osm4j.core.access.DefaultOsmHandler
Handler that handles, i.e., converts, nodes, ways, and relations. We parse these entities in distinct order, first all nodes, then all ways, and then all relations. this allows us to incrementally construct the network without backtracking or requiring the entire file to be in memory in addition to the memory model we're creating.- Author:
- markr
-
-
Constructor Summary
Constructors Constructor Description OsmNetworkHandler(OsmNetworkReaderData networkData, OsmNetworkReaderSettings settings)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
complete()
protected Map<MacroscopicNetworkLayerImpl,Pair<MacroscopicLinkSegmentType,MacroscopicLinkSegmentType>>
extractLinkSegmentTypes(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<String,String> tags)
extract the correct link segment type based on the configuration of supported modes, the defaults for the given osm way and any modifications to the mode access based on the passed in tags of the OSM wayprotected void
extractOsmWay(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<String,String> tags)
extract OSM way's PLANit infrastructure for the entire way, i.e., link, nodes, and link segments where applicable.protected Map<TransportLayer,Link>
extractPartialOsmWay(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<String,String> tags, int startNodeIndex, int endNodeIndex, boolean isPartOfCircularWay)
Extract OSM way's PLANit infrastructure for the part of the way that is indicated.protected Map<TransportLayer,MacroscopicLinkSegmentType>
getDefaultLinkSegmentTypeByOsmWayType(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<String,String> tags)
Collect the default settings for this way based on its highway typevoid
handle(de.topobyte.osm4j.core.model.iface.OsmNode osmNode)
construct PLANit nodes from OSM nodesvoid
handle(de.topobyte.osm4j.core.model.iface.OsmWay osmWay)
parse an osm way to extract link and link segments (including type).protected void
processCircularWays()
process all registered circular ways after parsing of basic nodes and ways is complete.void
reset()
reset the contents, mainly to free up unused resources
-
-
-
Constructor Detail
-
OsmNetworkHandler
public OsmNetworkHandler(OsmNetworkReaderData networkData, OsmNetworkReaderSettings settings)
Constructor- Parameters:
networkData
- the data used for populating the networksettings
- for the handler
-
-
Method Detail
-
getDefaultLinkSegmentTypeByOsmWayType
protected Map<TransportLayer,MacroscopicLinkSegmentType> getDefaultLinkSegmentTypeByOsmWayType(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<String,String> tags)
Collect the default settings for this way based on its highway type- Parameters:
osmWay
- the waytags
- the tags of this way- Returns:
- the link segment types per layer if available, otherwise null is returned
-
processCircularWays
protected void processCircularWays()
process all registered circular ways after parsing of basic nodes and ways is complete. Because circular ways are transformed into multiple links, they in effect yield multiple links per original OSM way (id). In case such an OSMway is referenced later it no longer maps to a single PLANit link, hence we return how each OSMway is mapped to the set of links created for the circular way
-
extractOsmWay
protected void extractOsmWay(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<String,String> tags) throws PlanItException
extract OSM way's PLANit infrastructure for the entire way, i.e., link, nodes, and link segments where applicable. The parser will try to infer missing/default data by using defaults set by the user- Parameters:
osmWay
- to parsetags
- related to the OSM way- Throws:
PlanItException
- thrown if error
-
extractPartialOsmWay
protected Map<TransportLayer,Link> extractPartialOsmWay(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<String,String> tags, int startNodeIndex, int endNodeIndex, boolean isPartOfCircularWay) throws PlanItException
Extract OSM way's PLANit infrastructure for the part of the way that is indicated. When it is marked as being a (partial) section of a circular way, then we only allow the presumed one way direction applicable when creating directional link segments. The result is a newly registered link, its nodes, and linksegment(s) on the network. The parser will try to infer missing/default data by using defaults set by the user.- Parameters:
osmWay
- to parsetags
- related to the OSM waystartNodeIndex
- to start parsing nodes fromendNodeIndex
- to end parsing nodes fromisPartOfCircularWay
- indicates if it is part of a circular way or not- Returns:
- created link (if any), if no link could be created null is returned
- Throws:
PlanItException
- thrown if error
-
handle
public void handle(de.topobyte.osm4j.core.model.iface.OsmNode osmNode) throws IOException
construct PLANit nodes from OSM nodes- Specified by:
handle
in interfacede.topobyte.osm4j.core.access.OsmHandler
- Overrides:
handle
in classde.topobyte.osm4j.core.access.DefaultOsmHandler
- Parameters:
osmNode
- node to parse- Throws:
IOException
-
handle
public void handle(de.topobyte.osm4j.core.model.iface.OsmWay osmWay) throws IOException
parse an osm way to extract link and link segments (including type). If insufficient information is available the handler will try to infer the missing data by using defaults set by the user- Specified by:
handle
in interfacede.topobyte.osm4j.core.access.OsmHandler
- Overrides:
handle
in classde.topobyte.osm4j.core.access.DefaultOsmHandler
- Throws:
IOException
-
extractLinkSegmentTypes
protected Map<MacroscopicNetworkLayerImpl,Pair<MacroscopicLinkSegmentType,MacroscopicLinkSegmentType>> extractLinkSegmentTypes(de.topobyte.osm4j.core.model.iface.OsmWay osmWay, Map<String,String> tags) throws PlanItException
extract the correct link segment type based on the configuration of supported modes, the defaults for the given osm way and any modifications to the mode access based on the passed in tags of the OSM way- Parameters:
osmWay
- the way this type extraction is executed fortags
- tags belonging to the OSM way- Returns:
- appropriate link segment types for forward and backward direction per network layer. If no modes are allowed in a direction, the link segment type will be null
- Throws:
PlanItException
- thrown if error
-
complete
public void complete() throws IOException
- Specified by:
complete
in interfacede.topobyte.osm4j.core.access.OsmHandler
- Overrides:
complete
in classde.topobyte.osm4j.core.access.DefaultOsmHandler
- Throws:
IOException
-
reset
public void reset()
reset the contents, mainly to free up unused resources
-
-