openelevationservice: enrich geometries with elevation

We published a new endpoint within the openrouteservice API ecosystem: openelevationservice. It queries a remote DEM for every vertex of a LineString or Point geometry. The underlying DEM is limited to SRTM v4.1 by CGIAR Consortium for Spatial Information as of now, though we’re working towards integrating more high-resolution datasets.

openelevationservice returns the altitude of plain latitude/longitude pairs which has many applications when combined with other routing and navigation data, like computing the steepness of a trail or estimating the battery usage of electric vehicles. This is made possible by querying an entire route or line at once.

The service lets you specify a range of input and output formats. The most convenient format for web developers will be GeoJSON, as this integrates neatly with other openrouteservice output formats and is the de facto standard for web based spatial exchange. Other formats include polyline (simple list of coordinates) and Google’s encoded polyline with additional z component (especially convenient in low bandwidth environments, like any German mobile network;)). E.g. with ors-py, enriching a route with elevation becomes very simple:

import openrouteservice as ors
clnt = ors.Client('your-key')  # insert your API key
route = clnt.directions([[8.675905, 49.418826],[8.736706, 49.486862]],
                        format_out="geojson",
                        geometry_format="geojson")
route_enriched = clnt.elevation_line(geometry=route['features'][0]['geometry'],
                                     format_in='geojson',
                                     format_out='polyline')

This is just an example of adding elevation to an arbitrary LineString geometry. Of course, with openrouteservice you could add the Z dimension already during route creation, passing elevation=true.

You can see the full documentation in the Github repository. You will also notice, that you can host openelevationservice on your own server/laptop as Flask service. Note, that you will have to have access to the SRTM FTP server, which you can request here.

To give the endpoint a try without needing to type any code, see its interactive documentation in our API playground. Note, you’ll have to sign up before and receive a free API key.

Happy requesting!

Comments are closed.