NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I am given a ISO 3361 Alpha-2 country code and a location name.

I'm trying to use Overpass to extract the geometries (or boundaries, or polygon) of that location. I don't know the location's specific administrative level (i.e. it could be a town, a city, a county, etc..., but not any lower resolution/division than that).

For example: DE + berlin DE + munich US + chicago FR + Levroux

Tried the following query, but got way more data than I need: (rel[boundary="administrative"][name="Berlin"][admin_level="4"];>;);(._;>;);out;

or {{geocodeArea:"DE"}}->.a; ( nwr["name:en"="Berlin"][boundary=administrative][type=boundary][admin_level="4"](area.a); ); out geom; I exported it as Geojson and projected it on map, but besides getting the boundaries of Berlin (type=boundary), I got some more nodes that I wasn't expecting.

So what is the best way to extract this data? Thanks!

asked 31 Jan '21, 13:29

RamidAshar's gravatar image

accept rate: 0%

Was "some more nodes" just the admin_centre node or actual nodes of the relation? Explain what "projected it on map" means? What map? uMap?

(31 Jan '21, 16:54) DaveF

yes, thats probably it (the admin_centre), but even more nodes in some weird places (some in the middle of the city, some on the boundaries). I converted to GeoJson and put it on for instance. maxerickson's answer seems to solve this issue for me.

(31 Jan '21, 17:40) RamidAshar

One way is to use explicit steps to fetch the ways and nodes instead of out geom:

out skel;

The way(r); line fetches only the ways from the boundary relation, and then out skel; fetches the nodes without their tags.

permanent link

answered 31 Jan '21, 15:22

maxerickson's gravatar image

accept rate: 32%

interesting. yes, it works. I got only the boundaries I needed. 1. Also, limiting to {{geocodeArea:"DE"}} seems to be really slow (I guess because the extra calls to OSM geocoding?) 2. Say I wanted all cities in Germany, should I simply remove the ["name:en"="Berlin"] part? (query goes timeout on UI).

(31 Jan '21, 17:43) RamidAshar

admin_level=4 is not for cities, so you'd have to do more than remove the name.

(31 Jan '21, 18:55) maxerickson

@maxerickson For some reason, back in 2012 This relation was defined as place=state

(06 Feb '21, 06:06) DaveF

Yes, it's a reflection of the political organization of Berlin.

(06 Feb '21, 15:41) maxerickson

Have you got 'Don't display small features as POIs.' under Settings>Map turned off?

Checking only for relations will return only relations & speed the search up a bit.

area["ISO3166-1"=DE]; // Germany
out geom;

PS Could you use the Code button when posting a routine. It makes it easier to read & copy/ppate/

permanent link

answered 06 Feb '21, 05:06

DaveF's gravatar image

accept rate: 16%

Follow this question

By Email:

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



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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:


question asked: 31 Jan '21, 13:29

question was seen: 79,006 times

last updated: 06 Feb '21, 15:41

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum