I am using Overpass Turbo, with extended syntax to query places in an area, usually a country, using the following syntax
{{geocodeArea:CH}}->.searchArea;
(
(node["place"]["name"~"^.+$"]["place"="country"](area.searchArea);)
);
out body;
Now, I would like to use this query against the open API directly.
I did figure out that it is possible but that the API is limited in regard to the extended syntax (the curly braces, it seems). So when I export the query from overpass turbo to text
(Export -> Query -> Text), I get the following output:
area(3600051701)->.searchArea;
(
(node["place"]["name"~"^.+$"]["place"="country"](area.searchArea);)
);
out body;
I can then POST this request to the API and it works.
Now my question:
I see that the text export converted the area code "CH" to the string/id 3600051701
.
Is it possible to have a lookup for these IDs? I might need to query many different countries and it would be convenient to have a lookup table somewhere.
I am new to OSM/Overpass.
Best Answer
When searching for country areas instead of using
{{geocodeArea:CH}}
I found that this also works:area["ISO3166-1"="CH"]
To retrieve a list of IDs of country areas you can query
which will return something like the following, with all relevant tags attached:
A way to get all country area IDs is to query for
boundary=administrative
&admin_level=2
(see the OpenStreetMap Wiki) in combination with the existence of theISO3166-1
tag:This results in 214 areas at this point. Leaving out the
ISO3166-1
tag results in a 391 results where there are a lot of duplicates and unwanted data. Some entries appeared to be Dutch islands, for example, which exist in addition to the main country Netherlands.