Routing with OSRM

OSRM ( is an opensource routing machine written in C++. It can create routes and turn-by-turn instructions from freely available OpenStreetMap data. OSRM runs in Docker containers so let’s see how it works. Lets suppose we want to bike in Utrecht from west to east, but we need a good route.

To get started we need to download some OpenStreetMap data, we’ll use the files on for that. Lets download the Utrecht OSM file (70MB).

$ wget

Now there are some processing steps, basically building a network from the OpenStreetMap data. There are 3 steps: extract, partition and customize.

Only the first step (extract) takes a bit longer (like a few minutes), other steps (partition, customize) are quick.

// extract

In the extract step we only are interested in biking routes (parameter -p /opt/bicycle.lua). Other options are foot or car.

$ docker run -t -v d:/proj/osrm:/data osrm/osrm-backend osrm-extract -p /opt/bicycle.lua /data/utrecht-latest.osm.pbf

// partition

$ docker run -t -v d:/proj/osrm:/data osrm/osrm-backend osrm-partition /data/utrecht-latest.osrm

// customize

$ docker run -t -v d:/proj/osrm:/data osrm/osrm-backend osrm-customize /data/utrecht-latest.osrm

Start a webserver on port 5000 with osrm-routed. Note the ‘algorithm’ parameter (‘mld’): mld is ‘multi level dijkstra’, other option is Contraction Hierarchies (CH).

$ docker run -t -i -p 5000:5000 -v d:/proj/osrm:/data osrm/osrm-backend osrm-routed –algorithm mld /data/utrecht-latest.osrm

And fire a request to bike from the west-side of Utrecht (4.9599903,52.0908023) to the east-side (5.1851206,52.07908):

$ curl http://localhost:5000/route/v1/driving/4.9599903,52.0908023;5.1851206,52.0790854?overview=full&geometries=geojson

A partly GeoJSON formatted result is returned, after some reshuffling omsmurfen we can visualize the route on :


There are a zillion other options in OSRM to play with,  so good luck with that Smile

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s