This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Overpass: find relations that have no members with a particular role

0

How do I make a query that returns me every admin_level=7 relation in Poland that doesn't have a member with admin_centre role?

This is a pre-requisite to another thing - After fixing these (if needed, I wanna find out) I want to list every place in Poland that should feature amenity=townhall, but has none. This is what I've got currently: http://overpass-turbo.eu/s/dJo

In this second query I also have to solve a problem: Some rural municipalities have their seat outside them, how do I exclude these? cf. https://en.wikipedia.org/wiki/Gmina

asked 15 Jan '16, 01:58

RicoElectrico's gravatar image

RicoElectrico
37161117
accept rate: 0%

edited 15 Jan '16, 21:42

aseerel4c26's gravatar image

aseerel4c26 ♦
32.6k18248554


One Answer:

2

I will focus on your first question atm. If possible, please move your other question to dedicated threads.

Here's how the query should look like

[timeout:600];

area[admin_level=2]["name"="Polska"][boundary=administrative]->.boundaryarea;

( rel(area.boundaryarea)[boundary=administrative][admin_level=7]; -

  ( node(r:"admin_centre")->.a;
    rel(bn.a)[boundary=administrative][admin_level=7]; 
  );
);

out geom;

Overpass Turbo Link: http://overpass-turbo.eu/s/dLT

A few words how this works:

  • We initially get a boundaryarea as defined per Poland's admin_level=2 boundary
  • Now we determine difference of all admin_level=7 boundaries in that area MINUS those admin_level=7 boundaries having an admin_centre node.

Read more about the recurse functions used in this query here.

Note that there are some relations returned outside of Poland. This is not a bug in the query, but rather some outdated areas on overpass-api.de. See this thread for details. It works just fine on our dev box with up-to-date areas.

answered 15 Jan '16, 20:11

mmd's gravatar image

mmd
5.7k15388
accept rate: 37%

Source code available on GitHub .