3

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).

2
  • 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 Jun 17 '15 at 15:51
2

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:json][timeout:90];
rel["route"="bicycle"]({{bbox}});
way(r);
way._["surface"="paved"];
out geom;
3
  • As I can see, there are no nodes will be loaded for ways. – dmitry.v.kiselev Jun 19 '15 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? – Rostranimin Jun 30 '15 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 Jul 5 '15 at 19:13
2

Try this:

[out:json][timeout:100];

//find ways which are members of relation or have highway=cycleway
//and write them as a
(
  relation[route=bicycle]({{bbox}});
  way(r);
  way[highway=cycleway]({{bbox}});
)->.a;

(
  //take ways from a and filter them by surface=paved
  way.a[surface=paved];
  //union with ways from a with surface=asphalt
  way.a[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

5
  • 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 Jun 17 '15 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. – Rostranimin Jun 17 '15 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 Jun 17 '15 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. – Rostranimin Jun 17 '15 at 16:37
  • I'm not familiar with out options, thanks for help, I've changed output. – dmitry.v.kiselev Jun 18 '15 at 6:33
0

You need to use boundbox (example Central London)

/*
This shows the cycleway and cycleroute network.
*/

[out:json];

> (   // 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)

4
  • 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 Jun 16 '15 at 19:16
  • hence the filter in qgis after – Mapperz Jun 16 '15 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 Jun 16 '15 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. – Rostranimin Jun 17 '15 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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