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.

1 Answer 1


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.
  • This is perfect. I'll give your first approach a try and get back to you. Thanks for your help friend!
    – maw269
    Jul 12, 2012 at 16:04
  • I've been playing around with the .config file to try and get some different results. I basically created a route with the default config and checked the geojson result for time and distance. Then I stopped the service and changed the .config marking all the tag.highway.xxx with 5 as the default speed and changed wtr.finalMask to bike. I restarted the service and checked the route with the geojson response. I got the exact same result with the same time and distance. Any thoughts? How do I edit the .config file to use with different vehicles?
    – maw269
    Aug 10, 2012 at 20:15
  • On my above comment, you have to modify the .config file then rebuild the graph. The wtr tags that were modified will then be implemented by the service.
    – maw269
    Aug 13, 2012 at 20:25
  • You do not need to modify the speed because you can use shortest path instead of fastest. This should give you the same results.
    – Carsten
    Aug 14, 2012 at 8:02
  • Thanks Carsten, I modified the default speed to get more accurate "Time" calculations in the GeoJSON response. However, I found that roads with a maxspeed tag in the OSM data took precedence over my modified default speeds in the .config file. Is there a way to ensure the default speeds are used. Since I am creating a walking route with a 5 kmh default speed, roads with a maxspeed tag (and a value of 80 kmh) in the OSM data are giving me faulty speeds/times for a walking pace. Of course I guess I could just code for this result if necessary.
    – maw269
    Aug 14, 2012 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.