I have this but I also wanted a column with the id of the relation to which each relation listed immediately belongs (parent). A search on OSM has in the result "...part of relation x", but how can I get that kind of information here through overpass-turbo? A parent of a relation x is the relation at the admin_level above which has that relation x as a child. I wanted something like: ::type, ::id, name, admin_level, ::parent id asked 28 Jul '18, 15:17 andrefrsilva |
One Answer:
You can use the
It is necessary to save the country into a result set, so that the set can be named in the convert statement. An alternate strategy is to make a second script where you recurse up relations and then post-process the json to get the parent information. This is ultimately the strategy the OSM website is using, the canonical information about relation membership is the list of children in each relation. It might be caching the reverse information somewhere, but that would be rebuilt each time a relation is edited. (edited to move answer up from comment) answered 28 Jul '18, 16:50 maxerickson edited 28 Jul '18, 18:14 showing 5 of 10 show 5 more comments |
I also thought about using something like this:
[out:csv(::type, ::id, name, admin_level, ::parent_id)]; area["name"="Portugal"][admin_level=2]->.parent; //somehow saving the id of this parent to parent_id//
then:
rel admin_level = 4 ; out;
but how?
Oh, I didn't realize that the parent would be available. Here's a step in the right direction, http://overpass-turbo.eu/s/ACK just need to figure out how to pull the Portugal id into it instead of writing "blah".
(Which I'm not sure is currently possible)
And here you go: http://overpass-turbo.eu/s/ACT
I found the answer in https://dev.overpass-api.de/blog/final_0_7_54.html, the blog there is I think still the best place for information about the recently released features.
Thanks a lot maxerickson! However, this way it just ends up as some "manual" input, and not the actual "parent" id. If I use admin_level=5 it continues to give out as "parent" what is now "grandparent".
The goal would be to use this with several levels (in my initial case, using admin_level bigger and then <<; to have layers of family before).
::id, name, admin_level, ::parent_id
id 1, name 1, level 1, parent 1 ... id 2, name 2, level 2, parent 2 (its actual parent) ...
The technique should work using other flow control, you'd just have to use lots of named sets and foreach loops to keep track of everything.
I'm pretty sure I'd do it in Python using json, where it'd be easy to build up mapping between children and parents.
Ok. And do you know if it is possible to use id instead of "name", since there might be different relations with the same "name" and ending up causing mistakes?
rel(id) will fetch the relation with that id.
Instead of rel[name="Portugal"][admin_level=2]->.c; .c map_to_area; rel(area)[admin_level=6][name]; what should I use? (Being id=295480)
You'd replace
rel[name="Portugal"][admin_level=2]->.c;
withrel(295480)->.c;
and keep the rest of it.Ok, thanks. This is what's lacking: https://overpass-turbo.eu/s/AFo