OpenStreetMap

Tweaking the OSM-And routing engine

Posted by Pieter Vander Vennet on 8 November 2017 in English. Last updated on 12 January 2019.

After some experimenting and help from the Belgian OSM Community, I figured out how to tweak the parameters for the routing engine and steer the navigation process. It seemed as if the technical documentation was missing, so lets write it here.

The parameter file: routing.xml

All parameters for the routing file are stored in a single XML.

You can find this XML on the OSMAnd github. Head over there, and download it. EDIT: By now, all the documentation has been included upstream. Everything you can read here, you an also find in the github routing.xml file. This diary entry can still serve as a gentle introduction.

This document should be placed in a place where OsmAnd will find it. As I chose ‘external storage’ to store my maps (settings -> general settings -> Data Storage Folder (under miscellaneous title), adding this custom routing is easy. Plug your phone in your computer and go to the path /sdcard/Android/data/net.osmand.plus/files. Copy routing.xml over.

Reading the parameter file

routing.xml is actually documented quite good! Read the docs there to get some general idea.

Adding an option to a profile

The parameters are split per profile. I edited the bicycle profile, as that is what I use most (also see my previous diary entry).

Over there, add a toggle, e.g., if you want to avoid sett surfaces:

    <parameter id="avoid_sett" name="Strongly prefer asphalt and paving stones" description="Tries to route around sett and cobblestone, ideal if riding with a cycling cart" type="boolean"/>

The id is the name you’ll use in if-statements, the name is what shows up in OSMAnd. Save the file as described above and restart OsmAnd. Start navigation to somewhere. If you click the settings (the cogwheel on the bottom when starting navigation), your new parameter should show up!

Tweaking weights

Routing considers three major aspects:

  • access
  • speed
  • priority

Each of those aspects has its own section in the xml; you can’t miss them.

Access

Access deduces if this road can be used or not. This is very hard: yes or no. If you want to create a profile to cycling with your toddler in the cart, and that toddler wakes up from the sett stones, you can add the following to avoid a condition in all cases:

   <select value="-1" t="surface" v="sett"/> -- never ever enter a set road

Of course, you might want to avoid unknown surfaces too:

   <select value="-1" /> -- Default: no access
   <select value="1" t="surface"/> -- only if a surface is known, allow access

And if you mix in the toggle, you’ll get:

   <if param="avoid_sett">
       <select value="-1" t="surface" v="sett"/>
  </if>

Speed

The other aspects are tweaked similarly:

Speed is the maximal practical speed on a certain road. For example, if sett slows you down to 5 km/h; then you can tell the navigation:

    <select value="5" t="surface" v="sett">

This is relative to other speeds. The default routing takes a default speed of 14.5 for cycling, so this would be way slower.

Priority

Priority is the preference of a road. If two routes are equal, the route with the highest priority is taken. However, as I modified both speed and priority in a similar way, it is hard to state the differences.

A sample use case

This custom routing can be tailored for your needs. See my other diary entry as an example and for the routes taken.

My custom routing.xml avoiding sett can be found here; the radical hiking by Joost Schouppe is over here.

Discussion

Comment from giggls on 9 November 2017 at 17:00

It is also possible to use external backend like brouter.

Comment from Pieter Vander Vennet on 9 November 2017 at 17:57

I have no idea, I only tried this with OsmAnd, as that is what I use…

Comment from giggls on 9 November 2017 at 18:06

Here is a manual on how to enable brouter in osmand (sorry German only) https://blog.natenom.com/2016/08/brouter-bringt-osmand-bei-dass-die-welt-nicht-flach-ist/

Comment from Pieter Vander Vennet on 10 November 2017 at 12:53

Hey,

I have no experience with BRouter. Perhaps drop them an email and ask about it?

Or perhaps just test it? Testing can be done relatively easily by hard blocking a road.

Also, I have no clue on how to encode height differences.

Comment from giggls on 10 November 2017 at 12:58

It was a sugesstion (by me) for people who want to do cycle routing to give brouter a try not a question.

Comment from CartoCharles on 26 November 2017 at 07:58

Thank you for the lightening. I was looking for a way to reduce the speed of the bicycle profile to get better ETA, it should be the solution and it brings a lot of tweak possibility.

I wonder if it is possible with a toggle to privilege or avoid some specific streets with there names. It could be fun in some cities to create tourism custom profiles.

Comment from Pieter Vander Vennet on 27 November 2017 at 12:50

Hey mygeomatic,

This should be possible; introduce a parameter as described, and use <select value="..." t="name" v="Street Name">

Comment from CartoCharles on 27 November 2017 at 17:02

Thank you Pieter, I’m looking forward to try it.

Comment from joost schouppe on 4 January 2019 at 19:45

The link to your custom routing XML is broken. My playthings are here: https://github.com/pietervdvn/pietervdvn.github.io/blob/master/routing_radical_hiking.xml Includes “prefer cycle routes when driving by car” (because they tend to be scenic and you want to drive slow), “prefer country roads” (because you are just cruising and only want to get to your destination eventually) and “radical hiking” (which will make detours to allow for as much paths as possible)

Comment from Pieter Vander Vennet on 12 January 2019 at 16:53

@joost: thx, I’ve finally found time to fix the links.

Log in to leave a comment