Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.
share|improve this answer
    
This is perfect. I'll give your first approach a try and get back to you. Thanks for your help friend! –  maw269 Jul 12 '12 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 '12 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 '12 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 '12 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 '12 at 20:42
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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