1

I am having trouble creating an OpenStreeMap Overpass XML combined polygon/bounding box query to return what I want. Can someone provide a simple example or correct the following XML?

I want to construct a query to retrieve data from multiple polygons or bounding boxes. Specifically, I want to retrieve all data within a small polygon and only certain data types, major roads, in a larger containing bounding box and return the combined result.

This XML shows conceptually what I want to do but is returning all data for the larger area rather than all data for the small area and major roads for the larger area:

<osm-script timeout="20" element-limit="1073741824">
    <union into="_">
        <!-- Smaller area, all data -->
        <polygon-query into="_" bounds="54.12 -2.779  54.143 -2.779  54.143 -2.761 54.12 -2.761" />
        <recurse from="_" into="_" type="up"/>
        <recurse from="_" into="_" type="down"/>
    </union>      
    <union into="_">
        <!-- Larger area, major roads only -->
        <bbox-query s="54.12" n="54.143" w="-2.779" e="-2.744" />
        <has-kv k="highway" v="motorway"/>   
        <recurse from="_" into="_" type="up"/>
        <recurse from="_" into="_" type="down"/>
    </union>
    <print from="_" limit="" order="id"/>
</osm-script>
0

I have edited it to work, hope it is what you want

<osm-script timeout="20" element-limit="1073741824">
<union into="_">
    <!-- Smaller area, all data -->
    <query type="node">
      <polygon-query into="_" bounds="54.12 -2.779  54.143 -2.779  54.143 -2.761 54.12 -2.761" />
  </query>
  <query type="way">
      <polygon-query into="_" bounds="54.12 -2.779  54.143 -2.779  54.143 -2.761 54.12 -2.761" />
  </query><query type="relation">
      <polygon-query into="_" bounds="54.12 -2.779  54.143 -2.779  54.143 -2.761 54.12 -2.761" />
  </query>
    <recurse from="_" into="_" type="up"/>
    <recurse from="_" into="_" type="down"/>
  <query type="way">
    <bbox-query s="54.12" n="54.143" w="-2.779" e="-2.744" />
    <has-kv k="highway" v="motorway"/>   
    </query>
    <recurse from="_" into="_" type="up"/>
    <recurse from="_" into="_" type="down"/>
</union>
<print from="_" limit="" order="id"/>

  • Thank you, that answers the question by helping me understand the logic much better so I am accepting it as the answer. I found that not all the data I expected mapped out. This appeared mostly due to missing nodes so I added the two recursion statements after each and every query, (not sure why that is necessary), and, for the motorways, had to add <recurse type="way-node"/>. In more complex examples this now giving more than I want in the outer area as it also bring in ways that share the same nodes, but nearly there. – MichaelCollinson Mar 1 '14 at 18:24

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.