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 |
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 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: but how?
(28 Jul '18, 17:15)
andrefrsilva
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)
(28 Jul '18, 17:36)
maxerickson
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.
(28 Jul '18, 18:00)
maxerickson
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". id 1, name 1, level 1, parent 1 ... id 2, name 2, level 2, parent 2 (its actual parent) ...
(28 Jul '18, 18:35)
andrefrsilva
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.
(28 Jul '18, 18:42)
maxerickson
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?
(28 Jul '18, 18:48)
andrefrsilva
rel(id) will fetch the relation with that id.
(28 Jul '18, 18:55)
maxerickson
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)
(28 Jul '18, 19:03)
andrefrsilva
You'd replace
(28 Jul '18, 20:24)
maxerickson
Ok, thanks. This is what's lacking: https://overpass-turbo.eu/s/AFo
(30 Jul '18, 16:00)
andrefrsilva
showing 5 of 10
show 5 more comments
|