I have the following script working so that in the resulting file I get a list of all districts and their ways and their nodes and the nodes themselves (but in the file it's in reverse order and with a flat hierarchy)

<osm-script>
  <query type="relation">
    <has-kv k="admin_level" v="9"/>
    <bbox-query e="1" n="2" s="3" w="4"/>
  </query>
  <union>
    <item />
    <recurse type="relation-way"/>
  </union>
  <union>
    <item />
    <recurse type="way-node"/>
  </union>
  <print />
</osm-script>

Now I can't figure out how to get this structured, so that in the end it's not flat but so that the relation nodes have their member nodes (type="way"), and so that the member nodes themselves have long-lat nodes (all structured)

asked 15 Apr '13, 20:45

SeWo's gravatar image

SeWo
31224
accept rate: 0%

edited 15 Apr '13, 21:02


I suggest

<osm-script>
  <query type="relation">
    <has-kv k="admin_level" v="9"/>
    <bbox-query e="1" n="2" s="3" w="4"/>
  </query>
  <foreach>
    <print />
    <recurse type="relation-way"/>
    <union>
      <item />
      <recurse type="way-node"/>
    </union>
    <print />
  </foreach>
</osm-script>

This prints for each relation first the relation and then the ways and nodes belonging to this relation. Ways and nodes that belong to more than one relation are repeated to appear after each relation where they belong to.

You can even do the same thing with the ways:

<osm-script>
  <query type="relation">
    <has-kv k="admin_level" v="9"/>
    <bbox-query e="1" n="2" s="3" w="4"/>
  </query>
  <foreach>
    <print />
    <recurse type="relation-way"/>
    <foreach>
      <print />
      <recurse type="way-node"/>
      <print />
    </foreach>
    <print />
  </foreach>
</osm-script>

Or let the ways and relations appear after their members:

<osm-script>
  <query type="relation">
    <has-kv k="admin_level" v="9"/>
    <bbox-query e="1" n="2" s="3" w="4"/>
  </query>
  <foreach>
    <recurse type="relation-way" into="ways"/>
    <foreach from="ways" into="way">
      <recurse type="way-node" from="way" into="nodes"/>
      <print from="nodes"/>
      <print from="way"/>
    </foreach>
    <print from="ways"/>
    <print />
  </foreach>
</osm-script>
permanent link

answered 16 Apr '13, 06:20

Roland%20Olbricht's gravatar image

Roland Olbricht
6.4k35986
accept rate: 35%

1

Again, note that as a way can belong to multiple relations and nodes can belong to multiple ways and relations, the resulting file will likely be bigger (and take longer to generate) than the flat version.

The hierarchy you're looking for doesn't exist in that form in OSM; depending on what you do, it might be less error-prone to embrace the OSM data structure directly.

(16 Apr '13, 09:23) Vincent de P... ♦

well it really builds some structures, but it's not what I wanted... I guess I'll build a script that parses all the data, builds a data-structure itself and then writes my kml file which is what I need in the end

(16 Apr '13, 17:14) SeWo

thanks anyway ;)

(16 Apr '13, 17:14) SeWo
Your answer
toggle preview

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:

×355
×12
×3
×1

question asked: 15 Apr '13, 20:45

question was seen: 2,579 times

last updated: 14 Mar '15, 14:41

powered by OSQA