I am interested in retrieving polygonal boundaries for all admin levels given a lat/long point.
I have a point - let's say (34.0500, -118.2500).
I would like to retrieve the city(admin_level=8)/state(admin_level=4)/country(admin_level=2) information along with the polygonal boundaries for each of these levels.
Currently, I am able to get the areas I am interested in using:
[out:json];
is_in(34.0500, -118.2500);
out;
{
"type": "area",
"id": 3600148838,
"tags": {
"admin_level": "2",
"border_type": "national",
"boundary": "administrative",
"name": "United States of America",
"type": "boundary",
"wikidata": "Q30",
"wikipedia": "en:United States"
}
},
{
"type": "area",
"id": 3600165475,
"tags": {
"ISO3166-2": "US-CA",
"admin_level": "4",
"boundary": "administrative",
"name": "California",
"type": "boundary"
}
},
{
"type": "area",
"id": 3600207359,
"tags": {
"admin_level": "8",
"boundary": "administrative",
"name": "Los Angeles",
"place": "city",
"short_name": "LA",
"type": "boundary"
}
}
However, I am unsure about how to get the polygonal boundaries for each of these admin_levels. I would like to do it as a single query if possible.
I tried:
area[name="Los Angeles"][admin_level=8][boundary=administrative]->.laarea;
rel(pivot.laarea);
out geom;
but this it seems to return data for every city in the world with the name "Los Angeles".
Is there a way to perform the above query using area ids from the previous query? Is there a better way to do this?
I've been using http://overpass-turbo.eu/ to test my queries.
You can combine is_in
with the rest of your query as shown in the following query:
is_in(34.0500, -118.2500);
rel(pivot)[boundary=administrative][admin_level~"^[248]$"];
out geom;
This will return all administrative boundaries on level 2, 4 and 8 for your location (34.0500, -118.2500). is_in
will simply produce a list of areas, which is used by the following (pivot).
overpass turbo link: http://overpass-turbo.eu/s/e01
When using explicit inputsets this can be also written as:
is_in(34.0500, -118.2500)->.areas;
rel(pivot.areas)[boundary=administrative][admin_level~"^[248]$"];
out geom;