I am trying to determine what the parent administrative area of any given area. The idea is that the closest parent is the administrative area with the highest/deepest admin_level that is shared as a parent by all points of the area boundary. Her the pseudo-algorithm I would like to be able to reproduce with the OSM API.
For a given area: For n in all nodes of its boundaries:
- parents are the administrative area the node n lies in
potential_parent = intersect(list of parents)
unique_parent = parent in potential_parent where admin_level == min(admin_level)
Unfortunately I wasn't able to define the intersection of the different sets of parents for each node composing the boundary of the area of interest
Hehre is the solution I came up with:
rel(426391772) -> .obj;
.obj>;
is_in;
area._[boundary=administrative] -> .parents;
foreach .parents -> .shared(
(.shared; - (.shared; - ._;););
);
out tags;
The for loop was my attempt to create the intersection set. But it doesn't return anything, while the .parents set is not empty. I suspect the difference is not working as I thing it would.
The rest of the request to filter the good area is as follow and seems to work:
area.shared[boundary=administrative](if:t["admin_level"] == max(t["admin_level"]));
If you have a better approach to this problem, I am happy to hear it.
Here is an example of my request with the turbo-overpass.