Help

Examples For Customizable Routing

In a previous post we described how to get started with customizable routing of the open source GraphHopper Routing Engine version 1.0. Today we’ll describe actual custom profiles by real world examples.

Disclaimer: custom profiles should still be considered a beta feature. Using them should be working, but details about the weight formula and the meaning of the different parameters is still subject to change. Also this feature will strongly benefit from community feedback, so do not hesitate with sharing your experience, custom profiles or problems you are running into! To share YAML files with us we suggest using a Github gist.

The format we use is in YAML that is accepted in the UI and also for the import. To use custom profiles per-request, against the endpoint /route-custom, you need to use JSON. (For import also JSON is accepted.)

Demo Server

Currently all examples are linked to our demo server with world wide coverage for car, bike and foot. Still the default route is shown and to see the effect of the customization you need to click on the “flex” icon near the “Search” button and enter the custom profile as YAML.

The basic structure of a custom profile is described in this documentation.

Safe Biking

Let’s start with a simple example from the previous post – it shows how to avoid primary roads:

priority:
    road_class: 
       primary: 0.1

Other possibilities are:

Avoid roads with max_speed greater than 50 km/h.
Avoid tunnels. Here going through a bridge on a cyclepath is picked instead of the tunnel without any safety.
Ride slower through e.g. pedestrian or living_street or footway. Here 5 minutes instead of 4. With the details array you request so called path details. They are shown in the UI when elevation is enabled (see the elevation widget in the bottom right corner).

Cargo Bike

The normal bike profile allows routing over steps in extreme cases. But a bike used for deliveries or children cannot be carried and should never be routed over this and so you exclude it with the road_class encoded value:

priority:
    road_class: 
       steps: 0.0

Further exclusions like ‘too narrow roads’ are possible:

Cargo bikes require a certain width

Walking for Tourists

Increase preference of the official hiking network and accept greater detours. As you can see in the custom profile all roads marked with “foot_network=other” are avoided and so e.g. “foot_network=regional” is used.

Economically Driving

There are many ways to save fuel. One is to drive slower and another is to prefer shorter routes. For v2.0 it is planned to include an influence from the elevation data. See how the custom profiles can look:

Drive slower on motorways and reduce max_speed for all roads.
Prefer shorter routes. Here the faster motorway is avoided. To do that you increase the distance_influence.

The distance_influence is independent of the road properties and does not influence the ETA. The default is 70 in seconds per 1km. Let’s assume a route that takes 1000sec and is 10km long, then a value of 30 means that I would like to drive maximum 11km to reduce the travel time to 970sec, or drive max 12km to reduce it to 940sec.

Now to another cool feature:

Avoid certain area like a city center where stop and go will cost a lot of fuel. For the area you can use a GeoJSON. Currently the areas are not displayed on the map you can use helper tools like geojson.io

Use the following area definition. You can also use the areas in the speed_factor to reduce the speed instead of changing the priority.

priority:
  area_cottbus: 0

areas:
  cottbus: 
     { "type": "Feature", "properties": {},
       "geometry": { 
         "type": "Polygon", 
         "coordinates": [[
           [ 14.31, 51.75 ],
           [ 14.34, 51.75 ],
           [ 14.34, 51.77 ],
           [ 14.31, 51.77 ],
           [ 14.31, 51.75 ]
         ]]
       }
    }

Truck

You can use custom profiles to give the car profile several “truck” attributes. First of all you should reduce the max_speed and the speed_factor and increase the distance_influence like we did for the “economically driving”.

Further changes to the car profile are required:

Exclude ferries and tracks. And avoid smaller roads like residential and tertiary.
Avoid road class links to avoid that the vehicle leaves the motorway. Probably this should be done different in real world.

Now to the most interesting properties like toll, width or height limitations:

Avoid toll costs. Here we say roads with the property toll=no get a priority of 1 and all the other values get 0.1. We could also explicitly say toll=all and toll=hgv get 0.1 but it can happen that future versions support more toll values and so this catch-all or “else” branch should be preferred.
Here we exclude roads where hazmat=no, hazmat_water=no, hazmat_tunnel is D or E, max_width is smaller than 3m, max_weight is smaller than 3.5t or max_height is smaller than 4m. The hazmat encoded values, especially hazmat_tunnel, do still seldom occur in OSM data. Other properties could be axle_load and max_length.

Conclusion

As already mentioned this feature will strongly benefit from your feedback. So do not hesitate to share your experience, custom profiles or problems you are running into!

Happy custom routing!