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, 20:51

nikotime's gravatar image

nikotime
1613
accept rate: 0%


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;
permanent link

answered 15 Jul, 11:57

MarcoR's gravatar image

MarcoR
6123718
accept rate: 27%

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

(16 Jul, 08:16) nikotime
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.

permanent link

answered 22 Aug, 18:50

DaveF's gravatar image

DaveF
2.4k6782110
accept rate: 13%

edited 22 Aug, 19:21

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×195

question asked: 14 Jul, 20:51

question was seen: 236 times

last updated: 22 Aug, 19:21

powered by OSQA