Thomas Perrin
Thomas Perrin

Reputation: 784

Get administrative borders with Overpass QL

I try to download the state borders of France (a few dozen states, not big data). Indeed I look for borders I can upload in my postgres database to localize POIs. OpenstreetMap seemed to be the good data source so I have tried to learn Overpass QL but it seems harder than I thought to do so... After some wiki reading I came to this:

way["name:en"="France"];
way["type"="boundary"];
way["boundary"="administrative"];
way["admin_level"="4"];

But the query endless runs... I am not sure about the query I made, is this the good syntax ? Thanks

Upvotes: 4

Views: 7564

Answers (2)

Suben Saha
Suben Saha

Reputation: 1848

You can use the following query. Adjust the admin level to your needs. Be careful while using the browser as it may return huge data. For me, it was 60 MB.

area["boundary"="administrative"][admin_level=2]["name:en"=France] ->.boundaryarea;
rel(area.boundaryarea)[boundary=administrative][admin_level~"^[3-5]$"];
out geom;

Upvotes: 0

mmd
mmd

Reputation: 3678

There are several issues with your query:

  1. Administrative boundaries are frequently modeled as relations, rather than ways in OSM. So querying for ways way[...] will not return the result you're looking for.
  2. To fetch elements which have have several tags, you need to combine them like [key1=value1][key2=value2]. You current query would query ALL ways WORLDWIDE with type=boundary and then again WORLDWIDE all ways with admin_level=4. Obviously this is both very expensive and not what you're looking for.
  3. out statement is mandatory to return some result. In your case, the query would in fact run, but it would never return anything.

My recommendation is to use the following query instead:

rel["ISO3166-2"~"^FR"]
   [admin_level=4]
   [type=boundary]
   [boundary=administrative];
out geom;

Try it in overpass turbo: http://overpass-turbo.eu/s/lnv

Upvotes: 10

Related Questions