I want to make custom router which while calculating route costs, would take into account additional features.

Here is the use case: Lets imagine paid motorway. Lets suppose there are 2 toll points. When router calculates route, it should, depending on user settings, find another way avoiding toll points, or inform user that his route crosses toll points here and here..

My first idea was to extend EdgeRouter2 class and override calcEdgeCost function, where I could check for given edge id in database and see if it contains toll points and act accordingly, but I want to be able to update my map and it looks like binding toll points table with edges cannot be done reliably neither by segment id nor osm_id (Is OSM_ID also part of osm2po graph?). Now I think it would be better to store toll points using lat,lon coordinates, calculate where those points are road network, and split edges at the given points.

Does this new approach make sense? What osm2po's classes should I use to accomplish this? I have a gut feeling that in this case using DefaultRouter2 instead of EdgeRouter2 would be better as it looks like it's more vertex centric - it doesn't have calcEdgeCost but it has (private) calcVertexCost function..

1 Answer 1


I have already played around with tolls in osm2po. Days! But it's not that easy. In OSM there are points tagged as toll-booths and toll-roads! In order to complicate things, some people have created polygons (buildings) tagged as toll-stations, which span over many lanes but are not connected to the network. Nevertheless, osm2po can take points and roads into account. So it's not that difficult as it seems at the first glance. Indeed, you'll have to overwrite some java-classes in osm2po. Namely the DefaultWayTagResolver and the DefaultNodeTagResolver. Both inform you about each parsed osm-tag and let you "invent" new classes and flags which you can take into account while routing. The routing algo has to be overwritten as well. Therefore overwrite the DefaultRouter for a first test.

Though, it might be possible to go an easier way. I'm just rethinking my comments above, and the DefaultWayTagResolver should alreay be able to mark streets as toll-roads. An example of how to overwrite the DefaultRouter is given in the plugins as source code. Look for "TrafficSignalsRouter".

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.