Overpass API – Fetching Multiple Nodes at Once Without Union

overpass-apiruby

I'm using Ruby and this GEM https://github.com/BrunoSalerno/overpass-api-ruby which allow us to query any endpoint.

Using the doc, https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL so far I have been able to query OSM to get some peaks which are above specific altitude.

node[place=peak](if:t['ele'] > 500.2)

but for the same bbox I'm trying to get other node, not a union of node, but additional node.

So I did try several things but so far, I'm here:

node[natural=peak](if:t['ele'] > 1400.2).node[place=village](if:t['ele'] > 500.2)

which results of a final query which is

[bbox:42.345044,2.697632,42.555304,3.269264][out:json];
node[natural=peak](if:t['ele'] > 1400.2).node[place=village](if:t['ele'] > 500.2);
(._;>;);
out body;

I also tried simply something like

[bbox:42.345044,2.697632,42.555304,3.269264][out:json];
node[natural=peak](if:t['ele'] > 1400.2);
node[place=village](if:t['ele'] > 500.2);
(._;>;);
out body;

but in this second case, only the last node (in this example, place=village) are being fetched, not the peak

What am I doing wrong?

Best Answer

You need to use a so called "union" statement, which combines the results of multiple query statement. More specifically, you need to add some round brackets to get both query results:

[bbox:42.345044,2.697632,42.555304,3.269264][out:json];
(      // <<< added union statement
  node[natural=peak](if:t['ele'] > 1400.2);
  node[place=village](if:t['ele'] > 500.2);
);     // <<< added union statement
out body;

See https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#Union for more details.