OpenStreetMap describes real world features with key=value tags. At the time of writing it has 74,029,011 distinct tags. That’s a lot of different ways to describe the world around us. Pop quiz: say you, a bicycle commuter, have the choice between these two roads: which would you prefer?

Images via Wikimedia. Left, Øyvind Holmstad / CC0; right, Chris Waits / CC BY

If you picked the asphalt, we’re with you. But how do we convey that knowledge to a routing engine?

Using OpenStreetMap tags we can reliably determine which OpenStreetMap objects are routable and rank them by order of preferability for traversal. You can see how we do this in the OSRM profiles, which are used to extract a graph of only routable ways from an OpenStreetMap extract.

A profile reads a given node or way’s metadata to determine whether it is routable and, if so, how fast, which is used as a heuristic to determine how important a way is. So in the case of the above road surface types, we can read a way’s surface tag and assign a different speed to affect its ranking in the contracted graph. That means we can pull out any of OpenStreetMap’s standard surface tags here:

surface_speeds = {
  ["asphalt"] = default_speed,
  ["cobblestone:flattened"] = 10,
  ["paving_stones"] = 10,
  ["compacted"] = 10,
  ["cobblestone"] = 6,
  ["unpaved"] = 6,
  ["fine_gravel"] = 6,
  ["gravel"] = 6,
  ["pebblestone"] = 6,
  ["ground"] = 6,
  ["dirt"] = 6,
  ["earth"] = 6,
  ["grass"] = 6,
  ["mud"] = 3,
  ["sand"] = 3
}

So in our bicycle routing stack, a road tagged surface=mud will almost never be returned in a route, unless it really is unavoidable.

We can use the same technique to determine traversal patterns for any transportation profile: to prefer bicycle lanes for a bicycle, to forbid driving in the wrong direction on a oneway street, to direct cars toward the fastest roads possible, to say that we walk more slowly in the sand. Using OpenStreetMap’s rich tagging schema we could use OSRM to extract any kind of topographical network for any number of transportation profiles – car, foot, bicycle, riverboat, horseback, you name it.

We just posted about our worldwide bicycle routing on Mapbox Directions. See the Directions API docs, try the Mapbox.js example, and contact us at help@mapbox.com to get access to the API.