5

I want to run following Overpass QL query in order to get way IDs of all buildings inside a polyon:

way(poly:"50.7 7.1 50.7 7.2 50.75 7.15")[building];
>;
out ids;

Since I'm using the osm-common library, I need to convert this script to Overpass XML. I did it using the convert form here.

The result:

<osm-script>
    <query into="_" type="way">
        <polygon-query bounds="50.7 7.1 50.7 7.2 50.75 7.15" into="_"/>
        <has-kv k="building" modv="" v=""/>
    </query>
    <recurse from="_" into="_" type="down"/>
    <print from="_" limit="" mode="ids_only" order="id"/>
</osm-script>

But when I run it, I get node IDs, not way IDs.

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="Overpass API">
<note>The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.</note>
<meta osm_base="2013-11-06T07:51:02Z"/>

  <node id="252553109"/>
  <node id="252553111"/>
  <node id="252553112"/>
  <node id="252553114"/>
  <node id="252553115"/>
  <node id="252553117"/>
  <node id="255302992"/>
  <node id="255302993"/>
  <node id="255302995"/>
  <node id="255763355"/>
  <node id="255763356"/>
  <node id="255763357"/>
  <node id="255763358"/>
  <node id="255763430"/>
  <node id="255763431"/>
  <node id="255763432"/>
...
  <node id="2519505892"/>
  <node id="2519505893"/>
  <node id="2519505894"/>
  <node id="2519505895"/>
  <node id="2519505896"/>

</osm>

How should I modify the Overpass XML query in order to get way IDs of the buildings?

5

When I manually enter a Query for ways Overpass turbo suggests an auto repair so as to also get nodes for the way. This then amounts to

way(poly:"50.7 7.1 50.7 7.2 50.75 7.15")["building"];
/*added by auto repair*/
(._;>;);
/*end of auto repair*/
out body;

see http://overpass-turbo.eu/s/1q1 .

Change out body to out ids if you really only want way IDs, but without the information which node belongs to which way.

2

if you only need the ids you should remove the line

<recurse from="_" into="_" type="down"/>

this line is converting your ways to nodes.

Note: you will only get id of the way, but not the geometry because co-ordinates are stored in nodes. If you need both you will have to union the way and nodes

<osm-script>
    <query into="_" type="way">
        <polygon-query bounds="50.7 7.1 50.7 7.2 50.75 7.15" into="_"/>
        <has-kv k="building" modv="" v=""/>
    </query>
    <!-- added by auto repair -->
    <union into="_">
      <item set="_"/>
      <recurse from="_" type="down"/>
    </union>
    <!-- end of auto repair -->
    <print from="_" limit="" mode="body" order="id"/>
</osm-script>

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.