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

I want to get the city boundaries within a specific country. The following query is fast but it's not bound to a country so that multiple city boundaries could be returned.

[out:json];(rel[name='Herne'][type=boundary];);out geom;

I tried this query but it's extremely slow:

( area["ISO3166-1:alpha2"="DE"];) ->.a;
rel[name="Herne"]
(area.a);
(._;>;);
out geom;

Is there a better and faster solution?

asked 21 Jun '18, 14:41

OsmStorm's gravatar image

OsmStorm
11112
accept rate: 0%


This should do it:

[out:json];
area['admin_level'='2']['name'='Deutschland'];
(relation['admin_level'='8'](area););
out geom;

My understanding is that this line limits the query to just Germany:

area['admin_level'='2']['name'='Deutschland'];

Then this line does the actual search of all cities within that area:

(relation['admin_level'='8'](area););

If it's still too slow, you could run multiple queries - one for each State (which exist at admin level 4), based on this example for Brandenburg:

[out:json];
area['ISO3166-2'~'^DE']['admin_level'='4']['name'='Brandenburg'];
(relation['admin_level'='8'](area););
out geom;
permanent link

answered 08 Aug '19, 00:20

JamesChevalier's gravatar image

JamesChevalier
1517713
accept rate: 25%

edited 08 Aug '19, 00:21

Is there maybe a way to detect which polygon belongs to which country by only going through the osm or geojson print? Maybe by help of the tags?

Herne Germany:

 "tags": {
    "TMC:cid_58:tabcd_1:Class": "Area",
    "TMC:cid_58:tabcd_1:LCLversion": "8.00",
    "TMC:cid_58:tabcd_1:LocationCode": "463",
    "admin_level": "6",
    "boundary": "administrative",
    "de:amtlicher_gemeindeschluessel": "05916000",
    "de:place": "city",
    "de:regionalschluessel": "059160000000",
    "name": "Herne",
    "name:prefix": "Stadt",
    "source": "http://wiki.openstreetmap.org/wiki/Import/Catalogue/Kreisgrenzen_Deutschland_2005",
    "type": "boundary",
    "wikidata": "Q2904",
    "wikipedia": "de:Herne"
  }

Herne Belgium:

"tags": {
"admin_level": "8",
"boundary": "administrative",
"name": "Herne",
"name:ru": "Херне",
"ref:INS": "23032",
"type": "boundary",
"website": "http://www.herne.be",
"wikidata": "Q567808",
"wikipedia": "nl:Herne (België)"

}

But here, I could only take the wikipedia entry and decide by the prefix "de" / "nl" whereas "nl" would be wrong if I was looking for a Herne in the Netherlands.

permanent link

answered 26 Jun '18, 07:56

OsmStorm's gravatar image

OsmStorm
11112
accept rate: 0%

I've tried myself your slow query and it took me 90 seconds. Bear in mind that it hasn't the filter [type="boundary"].

This one takes about 50 seconds, and does the same (it includes the [type="boundary"] filter):

[out:json];
relation[name="Herne"][type="boundary"](area:3600051477);
out geom;

From my experience so far with Overpass, it takes normally a similar time for queries over a country of the size of Germany. But maybe somebody has a faster solution.

permanent link

answered 23 Jun '18, 17:23

edvac's gravatar image

edvac
6652619
accept rate: 15%

Thanks for your answer! But why is this query so much slower than the first one? The first one takes like 1-2 seconds compared to 50/90 seconds. I guess it would be faster to take one coordinate per polygon (city) and check via another query if it's inside the given country or not. If someone finds a faster query or any other faster solution, please let me know.

(26 Jun '18, 07:06) OsmStorm

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:

×483
×362
×228

question asked: 21 Jun '18, 14:41

question was seen: 16,892 times

last updated: 08 Aug '19, 00:21

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