4

I am using area queries to find nodes with particular amenities Eg:-

[out:json]; 
area[name = "New York"]; 
node(area)[amenity=bar]; 
out; 

However the issue with this is that if I query the following:

[out:json]; 
area[name = "New York"]; 
(   
  node(area)[amenity=bar];
  node(area)[amenity=restaurant]; 
); 
out; 

The output includes only the first amenity, i.e. 'bar' even though there's a union. If I reverse the order to put 'restaurant' before 'bar' the output includes only restaurants. I also tried the same using XML syntax but in vain. Any ideas?

2 Answers 2

7

This can be easily fixed by storing the area in a named inputset (I use .a below) and referring to this inputset for both node statements:

[out:json]; 
area[name = "New York"]->.a; 
(   
  node(area.a)[amenity=bar];
  node(area.a)[amenity=restaurant]; 
); 
out; 

Link to Overpass turbo: http://overpass-turbo.eu/s/a2v

Some background information: In your example, (area) (short form for (area._)) refers to the default input set. An inputset is contains the nodes, ways, relations and areas, which are to be processed by the next statement.

Once the first node statement is processed, that default inputset in your query just contains nodes with [amenity=bar].

Important point here is, that the inputset no longer contains your New York area. The subsequent node statement doesn't have an area to work on anymore. Hence, you didn't get any restaurants in your query.

1
  • Hello mmd, thanks for dealing with this! I am not aware that this detailed information is containes in the OSM wiki about overpass unions, or yes? So where is the best place to add this additional information from your answer above?
    – stephan75
    Jun 22, 2015 at 16:38
0

Not sure about the exact problem, but the basic syntax is right. For example via overpass turbo:

[out:json][timeout:25];
(
  node["amenity"="restaurant"]({{bbox}});
  node["amenity"="toilets"]({{bbox}});
);
out body;
>;
out skel qt;

Please be aware that Overpass is for training only. If you want to create an production workflow with global coverage, it's reocmmend to build your own toolchain with planet.osm, osmosis, ...

1
  • Nope, there's a subtle issue with the query above. Although it is technically ok, it has semantic issues (see my other answer). Also, Overpass API for sure is not for training only. If you're concerned with load on the public instance, you can as well set up your own instance.
    – mmd
    Jun 21, 2015 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.