Is there a way to route different vehicles within OSM2PO? I would like to start the service with a config file and then turn different flags on/off depending on whether the route is for a bike or a car or a pedestrian.
Answer
Yes. But this decision has to be made dynamically. Meaning, you'll have to overwrite the DefaultRouter or alternatively implement one from scratch.
Let's prefer the first approach:
- Overwrite traverse(...) in order to get a reference to the Graph-Object. (do not forget to delegate to super.traverse() at the end)
- Overwrite calcEdgeCost(int index) The index-parameter points to the current edge while traversing. normally calcEdgeCost returns either graph.getEdgeCostsKm()[index] or graph.getEdgeCostsH()[index]
- The road type is accessible via graph.getEdgeFlags()[index] which returns the configured classId (e.g. 21 == Secondary)
- If you need more Properties, you might want to overwrite DefaultBuildInterceptor or implement another GraphBuildInterceptor.
car/bike/foot can be set in the Properties argument of traverse() before each call.
Alernatively you can implement one Router per UseCase
- or even one Graph per UseCase
- or even both.
No comments:
Post a Comment