This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Advanced overpass query

1

I have query:

< area-query ref="3600438171" /> 
< recurse type="node-way"/> 
< union> <query type="way"> 
< item/> 
< has-kv k="highway" v="cycleway" /> 
< /query> 
< recurse type="way-node"/> 
< /union> 
< print mode="meta" />

I need help with correct:

  • how to get parent relation of way
  • how to get tag UNION, i.e. result with < has-kv k="highway" v="cycleway" /> OR < has-kv k="cycleway" />

Thanks

This question is marked "community wiki".

asked 17 Dec '12, 13:06

hanoj's gravatar image

hanoj
6111
accept rate: 0%

edited 17 Dec '12, 13:37

scai's gravatar image

scai ♦
33.3k21309459


One Answer:

4

To get the union of both "highway=cycleway" and "cycleway", you can use a (nested) "union". Please note that we need a separate variable name "all_ways" in this case to use the found ways twice:

    <area-query ref="3600438171"/>
    <recurse type="node-way" into="all_ways"/>
    <union>
      <union>
        <query type="way">
          <item set="all_ways"/>
          <has-kv k="highway" v="cycleway"/>
        </query> 
        <query type="way">
          <item set="all_ways"/>
          <has-kv k="cycleway"/>
        </query> 
      </union>
      <recurse type="way-node"/>
    </union>
    <print mode="meta"/>

To get the parent relation of the way, please add a further recurse statement. This adds the parent relations only.

    <area-query ref="3600438171"/>
    <recurse type="node-way" into="all_ways"/>
    <union>
      <union into="selected_ways">
        <query type="way">
          <item set="all_ways"/>
          <has-kv k="highway" v="cycleway"/>
        </query> 
        <query type="way">
          <item set="all_ways"/>
          <has-kv k="cycleway"/>
        </query> 
      </union>
      <recurse from="selected_ways" type="way-relation"/>
      <recurse from="selected_ways" type="way-node"/>
    </union>
    <print mode="meta"/>

If you want further the child elements of this parent relation, please add yet another recurse. But this can return very much data if you have hit a road network, a national border or another large relation:

    <area-query ref="3600438171"/>
    <recurse type="node-way" into="all_ways"/>
    <union>
      <union into="selected_ways">
        <query type="way">
          <item set="all_ways"/>
          <has-kv k="highway" v="cycleway"/>
        </query> 
        <query type="way">
          <item set="all_ways"/>
          <has-kv k="cycleway"/>
        </query> 
      </union>
      <recurse from="selected_ways" type="way-relation"/>
      <recurse type="down"/>
      <recurse from="selected_ways" type="way-node"/>
    </union>
    <print mode="meta"/>

answered 18 Dec '12, 09:29

Roland%20Olbricht's gravatar image

Roland Olbricht
6.7k36489
accept rate: 36%

Thanx for you!

(18 Dec '12, 12:13) hanoj

Source code available on GitHub .