[GIS] Overpass Turbo Area Code Lookup

openstreetmapoverpass-api

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

(
  area["ISO3166-1"="CH"];
  area["ISO3166-1"="DE"];
  area["ISO3166-1"="FR"];
  area["ISO3166-1"="NL"];
  area["ISO3166-1"="SP"];
  area["ISO3166-1"="RU"];
);
(._;>;);
out; 

which will return something like the following, with all relevant tags attached:

  <area id="3600051477"/>
  <area id="3600051701"/>
  <area id="3600060189"/>
  <area id="3600062781"/>
  <area id="3602202162"/>
  <area id="3602323309"/>

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 the ISO3166-1 tag:

area["boundary"="administrative"]["admin_level"="2"]["ISO3166-1"];
out ids;

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.

Related Question