How to get parent administrative boundaries via OverPass API
Asked Answered
F

1

7

Having an administrative boundary relation of certain level, what is the best way to get parent level boundaries?

This works for Bratislava city part Petržalka: http://overpass-turbo.eu/s/ewU

[out:csv(::id,::type,"name","admin_level")];
rel(2208781);
(._;<<;);
out;

The result is:

@id     @type       name                    admin_level
14296   relation    Slovensko               2
388210  relation    okres Bratislava V      8
388265  relation    Bratislavský kraj       4
1702499 relation    Bratislava              6
2208781 relation    Petržalka               9

But it doesn't work for Vienna part Meidling http://overpass-turbo.eu/s/ex1

[out:csv(::id,::type,"name","admin_level")];
rel(1990596);
(._;<<;);
out;

the result

@id     @type       name        admin_level
1990596 relation    Meidling    9

Obviously, the problem is that there are no sub-relations defined in Vienna boundary relations. Is there any reliable way to find these parent-child relations?

Figge answered 21/2, 2016 at 21:35 Comment(3)
Any solution for this yet?Straitlaced
@DžanOperta No, sorry, I've abandoned this a long time ago.Reeder
@DžanOperta Look into my answer if you still looking for one.Cupola
C
1

Search Near then Down again

It is not the perfect yet, as I still don't know how to make recursive queries.

  1. Search for near-by higher administrative. (5Km seems good for close-by towns)

    [out:csv(::id,::type,"name","admin_level")];
    rel(id:1990596);
    relation["admin_level"~"8|7|6|5|4"](around:5000);
    (._;<<;);
    out;
    
    @id   @type   name    admin_level
    16239 relation    Österreich  2
    77189 relation    Niederösterreich    4
    109166    relation    Wien    4
    111858    relation    Bezirk Mödling  6
    111881    relation    Gemeinde Hennersdorf    8
    111887    relation    Gemeinde Breitenfurt bei Wien   8
    111946    relation    Gemeinde Perchtoldsdorf 8
    111948    relation    Brunn am Gebirge    8
    111956    relation    Gemeinde Vösendorf  8
    2668952   relation    European Union / Union Européenne / Europäische Union   
    12729625  relation    Eurozone / Zone euro    
    13376469  relation    Member States of the European Union / États members de l'Union européenne / Mitgliedstaaten der Europäischen Union
    
  2. Look for lower administrative inside each to verify

    [out:csv(::id,::type,"name","admin_level")];
    area["name"="Wien"]["admin_level"="4"]->.target_area;
    relation["admin_level"~"9|8|7|6|5"](area.target_area);
    (._;<<;);
    out;
    
    @id   @type   name    admin_level
    1990590   relation    Alsergrund  9
    1990591   relation    Hietzing    9
    1990592   relation    Innere Stadt    9
    1990593   relation    Josefstadt  9
    1990594   relation    Leopoldstadt    9
    1990595   relation    Mariahilf   9
    1990596   relation    Meidling    9
    1990597   relation    Neubau  9
    1990598   relation    Penzing 9
    1990599   relation    Rudolfsheim-Fünfhaus    9
    1990600   relation    Währing 9
    1991416   relation    Landstraße  9
    1991433   relation    Brigittenau 9
    1991434   relation    Donaustadt  9
    1991435   relation    Döbling 9
    1991436   relation    Favoriten   9
    1991437   relation    Floridsdorf 9
    1991438   relation    Hernals 9
    1991439   relation    Liesing 9
    1991440   relation    Margareten  9
    1991441   relation    Ottakring   9
    1991442   relation    Simmering   9
    1991443   relation    Wieden  9
    3980995   relation    Amtshaus für den 16. Bezirk 9
    

Long term solution

Best is still to contribute back directly and update parent relation. It wouldn't take much as long Wikidata/Wikipedia already has such info public. Or at least submit a OSM "note" on Meidling so someone has knowledge may fix it.

Update: not good enough yet

Using foreach, https://overpass-turbo.eu/s/1B5X

[out:csv(::id,::type,"name","admin_level")];

rel(id:2208781)->.t;

rel["admin_level"~"9|8|7|6|5|4|3|2"](around.t:5000)->.n;
//.n out;
foreach.n ->.e(
  .e map_to_area->.ea;
  rel(id:2208781)(area.ea)->.c;
  if (c.count(relations))
  {
    .e out;
  };
);
@id   @type   name    admin_level
14296 relation    Slovensko   2
388265    relation    Bratislavský kraj   4
1702499   relation    Bratislava  6
14613937  relation    Bratislavská arcidiecéza    6
388210    relation    okres Bratislava V  8
2208781   relation    Petržalka   9

Other town: https://overpass-turbo.eu/s/1B5Y

[out:csv(::id,::type,"name","admin_level")];

rel(id:1990596)->.t;

rel["admin_level"~"9|8|7|6|5|4|3|2"](around.t:5000)->.n;
//.n out;
foreach.n ->.e(
  .e map_to_area->.ea;
  rel(id:1990596)(area.ea)->.c;
  if (c.count(relations))
  {
    .e out;
  };
);
@id   @type   name    admin_level
16239 relation    Österreich  2
109166    relation    Wien    4
Cupola answered 22/9, 2023 at 8:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.