Hi,
I try to get all restaurants by cities in a region. In Overpass Turbo, I have : (http://overpass-turbo.eu/s/S9W)
[out:json][timeout:300];
{{geocodeArea:"Le Puy-en-Velay Auvergne-Rhône-Alpes France"}}->.searchArea;
(
node["amenity"="restaurant"](area.searchArea);
way["amenity"="restaurant"](area.searchArea);
relation["amenity"="restaurant"](area.searchArea);
);
out center;
This is working fine.
But I have hundred of cities in my region (all recovered from Wikidata) and I want to get restaurants for all cities.
I don't want to do it manually in overpass-turbo.eu tool, so I tried to export my "query" as an url. This is the generated url:
http://overpass-api.de/api/interpreter?data=%5Bout%3Ajson%5D%5Btimeout%3A300%5D%3B%0Aarea%283600120067%29-%3E.searchArea%3B%0A%28%0A%20%20node%5B%22amenity%22%3D
%22restaurant%22%5D%28area.searchArea%29%3B%0A%20%20way%5B%22amenity%22%3D%22restaurant
%22%5D%28area.searchArea%29%3B%0A%20%20relation%5B%22amenity%22%3D
%22restaurant%22%5D%28area.searchArea%29%3B%0A%29%3B%0Aout%20center%3B
As you can see in the generated url, the geocodeArea is converted to an area with ID 3600120067.
Is there a way to keep generated url with the geocodeArea as string, so I can write a script which will generate url for all cities ?
And, if not, where can I get this area ID ?
Thanks.
asked
01 Apr '20, 09:26
Aximem
11●1●1●2
accept rate:
0%
the algorithm to determine the ID is given in https://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Area_clauses_.28.22area_filters.22.29
If the names are consistent in OSM, you can use a query like
area[admin_level=8][name=NAME];
to access the area directly from Overpass API. Cities are usually admin level 8, but that can vary.Thanks for your help, I will give it a try
@maxerickson, this is working but I have to use exact city name. Some cities have the same name. For example there is 12 "Beaulieu" in France. That's why, with geocodeArea, I use "city + region + country". I cannot do this with area.
You can do an outer area query to deal with that, and then restrict the city query to that area. And then do another one to restrict the region query to a country, and so on.
Having nominatim deal with all that is nice. For some problems, using the admin_level based area query ends up being quite a bit simpler.