I'd like to extract a list of churches from OSM with their name, their coordinates and the name of the lower administrative division they belong to. I managed to get the first ones with:

out tags center;

I deliberately ignore nodes and relations as they don't seem relevant in this case.

I can't find a way to retrieve the name of the lower administrative division. Is there a way to do it?

  • 2
    I suggest to search for amenity=place_of_worship as well. There are 864226 of them (nodes and ways), while building=church only has 200886. For the admin division, you have to look into admin_level. It depends on your study area how deep they are detailed.
    – AndreJ
    Apr 24, 2017 at 15:16
  • Thanks for the suggestion. For the admin division, the problem is that I can't find a way to link the node/way/relation to admin_level or to perform reverse geocoding.
    – Ayack
    Apr 25, 2017 at 16:55
  • You have to do a spatial join between the buildings and admin polygons. Either use a postgis database, or any GIS software for that.
    – AndreJ
    Apr 25, 2017 at 19:07
  • @AndreJ: you can use Overpass API is_in for that purpose, see below.
    – mmd
    Apr 26, 2017 at 19:26

1 Answer 1


Similar to an example in the Overpass by Example library, I'd suggest to use the following query:

    .n is_in->.a;
    area.a[name][boundary=administrative][admin_level~"^[2-8]$"] -> .a;
    out center;
    convert way ::=::,
              ::id = id(),
              is_in=a.set("{" + t["admin_level"] + ":" + t["name"] + "}");

Step-by-step explanation how this query works:

  • It iterates over each building=church in your area
  • determines all nodes for each building
  • find out in which areas those nodes are (this is the actual georeferencing step)
  • filter out all areas with boundary=administrative and admin_level between 2 and 8 (you can adjust those if needed).
  • print out the center point of the church building way
  • generates an artificial element with the same way id and an additional element is_in, which lists all administrative boundaries the church is in.
  • prints out artificial element

Note that the query returns two ways for each church, one with a center node, and one with an is_in entry but without geometry. At this time, you have to manually merge those two ways. In a later version of Overpass API this will change, though, returning only one single result including geometry.

The line containing georeferencing information looks as follows:

Result is also available here for download: https://gist.github.com/mmd-osm/497252a37d174b187c7afc0238200fc5

  • Thanks a lot. I tried to output it to .csv with [out:csv(::id,"name",::lat,::lon,::is_in;false)];, but it never prints out the administrative boundaries. Any idea why?
    – Ayack
    Jul 24, 2017 at 19:48
  • the field name has to be "is_in", like "name". ::is_in doesn't exist as such, hence no result in the output.
    – mmd
    Jul 24, 2017 at 20:15
  • I tried it also but it doesn't work either...
    – Ayack
    Jul 24, 2017 at 20:25
  • How do you expect the administrative boundaries to show up in CSV format? Here's how the result looks here: gist.github.com/mmd-osm/10e867cfcfbe15fcef65867e64b6630e
    – mmd
    Jul 24, 2017 at 21:01
  • That's precisely what I wanted, thanks! How did you manage to print "is_in"?
    – Ayack
    Jul 25, 2017 at 18:52

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.