Help

Elevation data and OpenStreetMap

Handling elevation data and combine it with OpenStreetMap can be a pain. And indeed it was when we implemented this for GraphHopper roughly one year ago. But we really wanted to make it easy for our users. And it is very easy – you just need to set:

graph.elevation.provider=srtm

in the config.properties and GraphHopper will include elevation automatically! For the full elevation documentation please read this.

In GraphHopper Maps you can try it and see the elevation widget for every route for bike&foot:

elevation-widget

So GraphHopper will include elevation then automatically in

  • the import process and therefor also calculate more precise distances
  • the API where it adds three dimensional points (GHPoint3D) instead of just GHPoint
  • the web API where it uses a third dimension. As we also use a compact form called encoded polyline for this, you need the adapted decoding procedure when consuming the route and not using GeoJSON.

But to make a vehicle (e.g. bike) actually using the height information you need to tell it that uphill its slower than downhill via bike2. So you need a flag encoder with two weights per edge. But it is easy to enable:

graph.flagEncoders=bike2

With this logic in place it should be easy to improve our mountain bike profile to prefer up and down hill. It is important to note that for ‘preferring’ a specific feature it is not necessary to increase the speed. You can just tune this behavior via the priority implemented for bike and foot. Read more about how to write your own flag encoder here.

Other providers and more configurations

The nice thing about our modular approach is also that you can use a complete different provider like we do with CGIAR (improved SRTM data) or even inject your elevation data into the OSM. You just need to change this in the config

graph.elevation.provider=cgiar

Also you can have an in-memory or on-disc storage for this elevation data. E.g. to reduce RAM usage you use the default setting, but to speed up the import and not having SSD discs you set

graph.elevation.dataaccess=RAM_STORE

The nice thing is that you also can use our ElevationProvider implementations for you own Java application. Is it currently not separated from GraphHopper but it is relative separated and GraphHopper core is not big 🙂