简体   繁体   中英

How can I get all OSM ways and nodes tagged amenity, plus way nodes using the Overpass API?

I'm trying to get all the ways and nodes with an 'amenity' key, which works okay with a union, but I also need the nodes that make up a way, and the recurse tag isn't working as expected:

<osm-script>
<union>
<query type="way">
  <has-kv k="amenity" regv="."/>
  <bbox-query s="%s" w="%s" n="%s" e="%s"/>
</query>

<query type="node">
  <has-kv k="amenity" regv="."/>
  <bbox-query s="%s" w="%s" n="%s" e="%s"/>
</query>
</union>
<recurse type="way-node" />
<print/></osm-script>

The %s are placeholders. Thanks!

With your code, the results of the way query are replaced by the results of the recursion. Therefore, you should have the (usually untagged) nodes of the amenity ways in your output, but not the ways themselves.

Putting these in a union together, however, means that both the ways and their node end up in your output:

<osm-script>
  <union>
    <query type="node">
      <has-kv k="amenity"/>
      <bbox-query {{bbox}}/>
    </query>
    <query type="way">
      <has-kv k="amenity"/>
      <bbox-query {{bbox}}/>
    </query>
    <recurse type="way-node" />   
  </union>
  <print/>
</osm-script>

The {{bbox}} are placeholders for multiple parameters as in your example. If you want to test the modified query yourself, try this Overpass Turbo link .

(Also note that you can omit the catch-all regv parameters.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM