Search code examples
openstreetmap

OpenStreetMap API - find & visualize gravel roads


Does the API allow you to retrieve all roads/trails of a given type (eg gravel/unpaved)? If so, could you point me to some good tutorial that explain it's usage, if better than its own documentation?

I'd like to make a map where gravel/unpaved roads are highlighted, or live on its own layer.

Thanks in advance, and be merciful of the general question - I don't expect an in-depth answer, just a primer for my own research :)


Solution

  • The most popular API for running read-only queries on OpenStreetMap data is Overpass API. The results of an Overpass query can be easily displayed in typical map libraries like Leaflet.js (as well as offline GIS and cartography tools). When you test your Overpass queries, I recommend using the convenient "Overpass Turbo" online editor.

    To work with OSM data, it also helps a lot to know the OSM tags (attributes) related to the topic at hand. The OSM wiki documents this kind of information. For your use case, you are probably interested in the highway and surface keys.

    As a starting point for your own experiments, this Overpass query looks for highway ways (which includes roads, tracks, paths, etc.) which are known to have a gravel surface.

    Of course, there are alternative approaches – for example, you could render your own maps based on a custom map style where roads look different depending on their surface. This would involve very different tooling. But showing Overpass API results in front of a regular OSM map as the background gets you quite far, and may be entirely sufficient for your needs.