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

I have written a query to get a countries sub regions by first querying for the country relation, then recursing down, then filtering the relations by role=subarea, query:

[out:json];
rel['ISO3166-1'='{countryCode}']->.c;
.c >>;
(rel(r:'subarea');.c;)->.a;
.a out meta bb;

This query works well for countries such as Spain ({countryCode}=ES) and Portugal (PT) and it is very easy to extract a hierarchy from output as relations have an id and members have a relation to the same id.

However, countries such as Croatia (HR) only return the country relation .c when this query is executed, inspection of the result shows that the Croatia relation has no member relations with the subarea role, and thus the recursion returns an empty set.

It is important to me that I am able to build a hierarchy from the results and I have not been able to create a query which returns a nations regions for a country such as Croatia where the country relation has no subareas.

I do not mind executing another query or going to another openstreetmap source if the first query should return only the country relation.

Do you know of any way to query Overpass to get a heirarchy of a countries sub regions when the relations members have no subarea role? Or another source for the information? Or some other way of achieving the same result?

Any help is greatly appreciated.

asked 24 May '18, 09:49

dreggers's gravatar image

dreggers
11112
accept rate: 0%


Here's a query that fetches objects tagged with admin_level from a given country:

area[admin_level=2][int_name=Croatia]->.search;
(way(area.search)[admin_level=4];
 rel(area.search)[admin_level=4];
);
out center;

Overpass-API creates the area features for use in queries by processing OpenStreetMap objects with tags that indicate they should be treated as an interesting area. There should be one for every administrative region in OSM.

permanent link

answered 25 May '18, 23:22

maxerickson's gravatar image

maxerickson
12.7k1083176
accept rate: 32%

That was very helpful. Thank you very much!

(02 Aug '18, 17:11) rene78

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
×236
×65
×58
×54

question asked: 24 May '18, 09:49

question was seen: 4,150 times

last updated: 02 Aug '18, 17:11

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