NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

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


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"/>
permanent link

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

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×483

question asked: 17 Dec '12, 13:06

question was seen: 4,051 times

last updated: 18 Dec '12, 13:19

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum