Maximum nesting of administrative boundaries

I have an oddity question, that I’m wondering if someone can figure out how to answer.

So you have country boundaries tagged boundary=administrative + admin_level=2, and then states at admin_level=4 and so forth. So, if you have a city within a county within a state within a country, that’s four total levels.

I am wondering what is the deepest nesting that exists in the database? Does anyone have a technique that might work to be able to determine this?

I’m not entirely sure what the specific issue is with your question.

As I know that the ‘admin_level’ in OpenStreetMap varies by country.
Currently, the maximum documented value for
(administrative) admin_level is 11, as detailed in the wiki.

see big table:
Tag:boundary=administrative - OpenStreetMap Wiki.

In practical terms, I would consider
admin_level=11 as the maximum sensible level to work with.

EDIT:

That is not the question I am asking.

I am asking what is the deepest level of nesting that exists in the database. I am looking for specific cases where a boundary is hierarchically contained within N successively higher-level administrative boundaries.

What is the largest value of N?

Sure there are large values of admin_level, but not every number from 2-11 is necessarily used.

1 Like

Looking at the cases where high numbers are used in taginfo, I found a 5-stack:
Poland > Kuyavian–Pomeranian Voivodeship > Bydgoszcz County > Gmina Białe Błota > A rope in someone’s garden.

Not sure how valid the last step is, but it definitely exists in the database. Not much else interesting in the 13+ numbers.


The Philippines regularly goes to 5: Philippines > Region > Province > Municipality > Barangay

2 Likes

In Greece, we have 7 layers in total (and currently the maximum we can map, meaning no other administrative layer is missing from it):
For example the railway station of Patras is within Greece > Decentralized Administration of Peloponnese, West Greece and Ionian > Region of West Greece > Regional Unit of Achaea > Municipality of Patras > Municipal Unit of Patras > 1st Commune of Patras

1 Like

Looking at the table linked by @ImreSamu only the Philippines are using every level from 2 to 11 :slight_smile:

In Germany I found a 8-stack without a rope in someone’s garden:

Germany(2) → Baden-Württemberg(4) → Regierungsbezirk Stuttgart(5) → Rems-Murr-Kreis(6) → Vereinbarte Verwaltungsgemeinschaft der Stadt Backnang(7) → Weissach(8) → Oberweissach(10) → Wattenweiler(11)

only missing the admin_level=9

2 Likes

That’s a fun challenge!

The Philippines are even using level 12! But that doesn’t automatically mean that they are using every admin level everywhere in the country…

How about this one?

Brazil (2) > Região Sul (3) > Santa Catarina (4) > Região Geográfica Intermediária de Chapecó (5) > Região Geográfica Imediata de Chapecó (7) > Chapecó (8) > Figueira (9) > Vederti (10) > Loteamento Vederti 2 (11) > Quadra 5426 (12) > uhh… this forest (13)?

I used spatial queries (which admin boundary is within which one?) to construct a directed acyclic graph of admin boundaries. I made each admin boundary a graph node, then connected them with an edge if they were within another admin boundary. The answer is the longest path in the graph.

Edit: Here is the code, in case someone would like to do something similar. Takes only a few minutes to run (once you have downloaded and converted the planet file into the format required by Geodesk) !

Code
from geodesk import *
import networkx as nx
planet = Features("planet.gol") # this file has to be created from an .osm.pbf file first

# create empty graph and a root node
G = nx.DiGraph()
G.add_node("world")

# make each admin boundary into a graph node
admin_boundaries = planet('a[boundary=administrative][admin_level][type!=multilinestring]').relations
G.add_nodes_from(admin_boundaries)

# connect each country node to the root node
for country in planet('a[boundary=administrative][admin_level=2][type!=multilinestring]').relations:
    G.add_edge("world", country)

# connect each admin area to all the higher-level admin areas within it
for a in admin_boundaries:
    if str(a.admin_level).isdigit():
        for sub_boundary in planet('ar[boundary=administrative][admin_level > ' + str(a.admin_level) + '][type!=multilinestring]').relations.within(a):
            G.add_edge(a, sub_boundary)

nx.dag_longest_path(G)
7 Likes

@osmuser63783, I think that’s a solution for the problem - a bit overhead inclusive :slight_smile: