How do I construct an Overpass query to find data on Openstreetmap which is both part of a relation and has itself a specific attribute?

Specifically: I'm wanting to find sections of cycle route (in a route relation) AND which are surfaced a particular way using Overpass - accessed using the Quick OSM plugin on QGIS.

So in terms of the OSM data I'm looking for a relation with type=route and route=bicycle http://wiki.openstreetmap.org/wiki/Cycle_routes#Relations

But I want to limit this by surface - lets say surface=paved or surface=asphalt http://wiki.openstreetmap.org/wiki/Key:surface

Ideally I'd like to do this using the QGIS Quick OSM plugin - but if necessary I'm happy to use the Overpass Turbo website.

I'm well out of my depth on getting the syntax correct for this (although I've used all these systems for simpler queries).

  • Just a hint: Not all ways have a surface tag. Retrieving only ways with surface=paved or surface=asphalt will ignore many ways that don't have a surface tag but are paved in reality. Depending on the geographica are you can assume surface=paved for many highway values.
    – scai
    Commented Jun 17, 2015 at 15:51
  • This question at help.openstreetmap.org
    – scai
    Commented Jun 17, 2015 at 16:30

3 Answers 3


I was really wondering how to do this, so I asked the question at help.openstreetmap.org as @scai suggested, and Roland Olbricht (developer of Overpass API) was kind enough to supply the query pasted below. Read the full answer for an explanation.

out geom;
  • As I can see, there are no nodes will be loaded for ways. Commented Jun 19, 2015 at 7:47
  • I'm finding it impossible to understand the detail of the answer Roland Olbricht provided, and can't find a simple intro to the query language. I'd be grateful if someone could confirm if my understanding of this query is correct - I think it means (statement by statement): Output will be json. Timeout of 90s. Look for relations (route=bicycle) within the current map canvas. Now get the ways which make up the selected relations. From these select the ways where surface=paved. Output all the data including the geometries. Is that correct? Commented Jun 30, 2015 at 10:43
  • @Rostranimin: the explanation is basically correct. out geom; will however just return the result of way._["surface"="paved"];. The whole statement looks more complicated than the one posted here (overpass-turbo.eu/s/9Zf), to speed up processing and work around some performance issues.
    – mmd
    Commented Jul 5, 2015 at 19:13

Try this:


//find ways which are members of relation or have highway=cycleway
//and write them as a

  //take ways from a and filter them by surface=paved
  //union with ways from a with surface=asphalt

  //you could add more surface variants here
  //by adding way.a[surface=value];

  // get nodes for ways

out meta;

This query on overpass-turbo http://overpass-turbo.eu/s/9YS

  • I would recommend to use a global bbox here. Otherwise the query will return ways outside of the current bbox, which happen to be part of some larger cycling route. Example: overpass-turbo.eu/s/9Zg
    – mmd
    Commented Jun 17, 2015 at 15:48
  • Looks good - but it only returns the lines and I think the ID of the way. Can we make it also return the data (or some of the data) from the ways? Sorry - I realise my inexperience with Overpass will be apparent in asking this. Commented Jun 17, 2015 at 15:52
  • Full details are available via out meta; instead of out skel qt; in the last line. A bit less verbose, but still with some details for ways: overpass-turbo.eu/s/9Zh
    – mmd
    Commented Jun 17, 2015 at 15:55
  • That works. Thank you. To summarise mmd's two additions - a new additional second line [bbox:{{bbox}}]; and a changed final line out meta; instead of out skel qt; - I still can't work out how to set this up using the Quick OSM plugin for QGIS, but no matter. Exporting from Overpass Turbo is simple. Thanks again. Commented Jun 17, 2015 at 16:37
  • I'm not familiar with out options, thanks for help, I've changed output. Commented Jun 18, 2015 at 6:33

You need to use boundbox (example Central London)

This shows the cycleway and cycleroute network.


> (   // get cycle route relatoins  
> relation[route=bicycle]({{bbox}})->.cr;   // get cycleways  
> way[highway=cycleway]({{bbox}});  
> way[highway=path][bicycle=designated]({{bbox}}); );
> out body;
> >; out skel qt;

![enter image description here][1]

raw (this will take a few second too load) http://overpass-api.de/api/interpreter?data=%2F*%0AThis%20shows%20the%20cycleway%20and%20cycleroute%20network.%0A*%2F%0A%0A[out%3Ajson]%3B%0A%0A%28%0A%20%20%2F%2F%20get%20cycle%20route%20relatoins%0A%20%20relation[route%3Dbicycle]%2851.50788104332645%2C-0.1278555393218994%2C51.51368359725126%2C-0.11653661727905273%29-%3E.cr%3B%0A%20%20%2F%2F%20get%20cycleways%0A%20%20way[highway%3Dcycleway]%2851.50788104332645%2C-0.1278555393218994%2C51.51368359725126%2C-0.11653661727905273%29%3B%0A%20%20way[highway%3Dpath][bicycle%3Ddesignated]%2851.50788104332645%2C-0.1278555393218994%2C51.51368359725126%2C-0.11653661727905273%29%3B%0A%29%3B%0A%0Aout%20body%3B%0A%3E%3B%0Aout%20skel%20qt%3B

In QGIS you can filter by surface (it will be quick in QGIS than using the Overpass API)

  • I don't think this quite does it. You get ways in cycle route relations, but doesn't limit those ways by surface type.
    – neuhausr
    Commented Jun 16, 2015 at 19:16
  • hence the filter in qgis after
    – Mapperz
    Commented Jun 16, 2015 at 19:28
  • 1
    This should be completely doable in an Overpass query (but I'm not familiar enough with it). If nobody here comes up with such a query then try asking at help.openstreetmap.org.
    – scai
    Commented Jun 16, 2015 at 19:36
  • Thanks - as neuhausr says I'm looking for the knowledge about how to write a query which avoids the approach in your answer Mapperz. It's a very valid approach in many circumstances (which I already understand) but potentially this would involve a very large amount of data only a tiny part of which I'd want. I'd like to know how to do the query at the Overpass stage - not least because I guess this puts less demand on the OSM server. The point about asking at help.openstreetmap.org is noted scai. Commented Jun 17, 2015 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.