Tac Tacelosky
Tac Tacelosky

Reputation: 3426

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!

Upvotes: 0

Views: 2180

Answers (1)

Tordanik
Tordanik

Reputation: 1353

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.)

Upvotes: 1

Related Questions