I need to match cities/postal codes from a large dataset with their regions (NUTS3 if available, otherwise administrative divisions as can be found here https://en.wikipedia.org/wiki/List_of_administrative_divisions_by_country). Cities can be all around the world and have all sizes.

I've come across that OSM provides regions for all(?) cities. Searching for a small village in Germany ('Unterkirnach'), I get the following result: Village Unterkirnach, Verwaltungsgemeinschaft Villingen-Schwenningen, Schwarzwald-Baar-Kreis, Regierungsbezirk Freiburg, Baden-Württemberg, Germany

That's all the information I need, namely administrative divisions on several levels, and it also seems to work for small towns, e.g., in China.

However, I would need to extract a list/table of towns and their assignment to regions worldwide in order to upload it to my database and to look up the regions of the cities in my dataset. At this point, I do not want to do any 'fancy' stuff I do not understand, I simply want to create a table with as many cities as possible and columns for their administrative regions on different levels.

Does anyone have an idea how to do this?

  • Did you already evaluate to use Nominatim for this task? Osm search is based on it and if you find results useful, you should set up your own instance due to the large amount of queries.
    – mmd
    Commented Jul 6, 2017 at 15:47

1 Answer 1


You could use the useful OSM key [is_in=*] to get a list of the administrative regions where your place is situated.

You can query the OSM data using the overpass API. You can output some data directly in a csv table. See the following query to request the name of the place + the is_in tag for Unterkirnach in Germany and get the result in a csv format. Here's the overpass-turbo link: http://overpass-turbo.eu/s/qcO

[out:csv(name, is_in)][timeout:50];
out body;

For querying several places, you may run some overpass query into a loop. See this post for some inspiration.

However, this won't work if there is no is-in tag. But it should be available for major cities worldwide.


  • 2
    Better use boundary relations instead for this task, is_in is no longer current state of the art! Also running the query in a loop is not recommended as described in that post, it will very quickly return 429 http errors.
    – mmd
    Commented Jul 6, 2017 at 14:32
  • @mmd, thanks for the comment. How can we make a kind of loop using the overpass API. I mean, in this case, if we have a list of names, how to recursively pass the names into overpass queries?
    – juminet
    Commented Jul 6, 2017 at 14:45
  • 1
    foreach would be the approach to avoid externally driven looping, but given the task at hand (global scale geocoding), I wouldn't recommend overpass API at all, unless you set up your own dedicated instance. Still geocoding is best covered by Nominatim and friends.
    – mmd
    Commented Jul 6, 2017 at 15:49

Your Answer

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

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