2

How can I use the overpass-API to recursively get all nodes and their coordinates which belong to the ways of an relation? I need this to draw bounding polygons of all the postal areas inside a city.

I have the following query:

<osm-script>
<area-query ref="3600062649" />
  <recurse type="up" />
  <query type="relation">
     <item />
     <has-kv k="boundary" v="postal_code" />
  </query>
<print />
</osm-script>

This returns all relations with postal boundary inside the queried area and all the ways of these relations, however it does not return the nodes/coordinates of the points which make up these ways:

<relation id="1300371">
   <member type="way" ref="51702433" role="outer"/>
   ...
   <tag k="note" v="04451 Borsdorf"/>
   ...
</relation>
<relation>
....
</relation>

I would like to get a list of postal areas with their nodes, like this:

<relation id="1300371">
   <member type="way" ref="51702433" role="outer">
      <node id="323735839" lat="51.3751873" lon="12.5689796" />
      .... 
   </member>
   <tag k="postal_code" v="04451"/>
   ...
</relation>

The tag with the postal code should still be included so I can distinguish all received postal areas.

2 Answers 2

2

I would recommend the following approach: it returns coordinates for ways' nodes 'in place', like you described in your question.

The only thing, which is missing in the output is the technical OSM node-id (ref). I assume that for use case of drawing some boundary area on a map, this is most likely not needed. If you take a look at the screenshot below, overpass turbo is drawing all postal code areas on the map without any issue.

area(3600062649);
rel(area)["boundary"="postal_code"];
out geom;

http://overpass-turbo.eu/s/7In

enter image description here

Example output:

  <relation id="1301656">
    <bounds minlat="51.3145882" minlon="12.2366519" maxlat="51.3391521" maxlon="12.3034696"/>
    <member type="way" ref="87537618" role="outer">
      <nd lat="51.3179538" lon="12.2426125"/>
      <nd lat="51.3178723" lon="12.2414464"/>
      <nd lat="51.3176008" lon="12.2399198"/>
    [...]
    </member>
    [...]
    <tag k="boundary" v="postal_code"/>
    <tag k="note" v="04205 Leipzig"/>
    <tag k="postal_code" v="04205"/>
    <tag k="postal_code_level" v="8"/>
    <tag k="type" v="boundary"/>
  </relation>
1
  • Thx, that is what I was looking for. I managed to find kind of a workaround by querieng every postal area on its own and joining down to the nodes... 'out geom;' is exactly what I needed here.
    – Philipp
    Feb 18, 2015 at 8:24
0

Try the following:

  1. Copy your overpass-api query to clipboard
  2. go to https://overpass-turbo.eu
  3. paste your query in the left screen by deleting any other content before there.
  4. Run your query on that service,
  5. wait that an alert comes up about missing information to display nodes from OSM objects
  6. agree to auto-repair your query
  7. Re-run your query in overpass-turbo
  8. on the left side, switch from map view to data view
  9. Tell us whether that is the result you want.
1
  • Hm, I did not find a way to repair my query, I don´t think their was any problem with it (beside not returning the data I need) I don´t need to see the boundaries on the map on the overpass-api. I want to draw them myself in JS later.
    – Philipp
    Feb 18, 2015 at 8:26

Your Answer

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

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