This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Problems with limiting overpass results to admin boundaries

0

Hey all,

whilst I thought I was somewhat getting the hang over the Overpass API, a fairly basic usecase has me stumped!

I want to extract the enclosing administrative boundary when providing a lat and long, looking to extract levels 10, 9 and 8.

I have been able to extract all surrounding relations by doing the following query, which pulls back far too much information including the county, country and UK as a whole:

   [timeout:25][out:json];
    is_in(52.0246,0.80801)->.a;way(pivot.a);out tags ;relation(pivot.a);out tags bb;

I have tried to limit the results with:

area['admin_level'='10'];

and various relations but that hasn't limited the results at all. Could someone please help? Much appreciated!

asked 14 Jul '21, 20:51

nikotime's gravatar image

nikotime
16113
accept rate: 0%


2 Answers:

1

If you want only those relations tagged with admin_level=10 you can say it when requesting them:

[timeout:25][out:json];
is_in(52.0246,0.80801)->.a;
relation(pivot.a)[admin_level=10];
out tags bb;

If you want even those with admin_level 8 and 9 then the code gets slightly larger:

[timeout:25][out:json];
is_in(52.0246,0.80801)->.a;
relation(pivot.a)(if:t["admin_level"]>=8 && t["admin_level"]<=10);
out tags bb;

answered 15 Jul '21, 11:57

MarcoR's gravatar image

MarcoR
6873820
accept rate: 23%

Thats absolutely spot on. Thanks so much Marco for your help!

(16 Jul '21, 08:16) nikotime

0
is_in(52.0246,0.80801);
rel(pivot)[admin_level~"[2,8,9,10]"];
out geom;

No requirement to store output in a variable (a) if only to be used once. Pivot will used the default output.

Regex is used to filter the required admin_level. Note the 'something like' symbol.

Pivot converts area to objects.

Edit:

To output just the tags there's no need to pivot

is_in(52.0246,0.80801);
area._[admin_level~"[2,8,9,10]"]; 
out tags;

PS If you're just wanting to output a list, maybe take a look at out:csv.

answered 22 Aug '21, 18:50

DaveF's gravatar image

DaveF
3.3k8498133
accept rate: 16%

edited 22 Aug '21, 19:21

Source code available on GitHub .