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

Hello, I am fairly new to overpass but I attempt to do a tree traversal of boundaries of admin_levels for a given country.

For example: For UK, I want the UK border. Then on next level the borders of Wales, England, Scotland, Northern Island. Then on next level, for example inside England, I want the regions of England. Etc. At the end I would have a tree structure. I don't need to have all data all at once, but would be sufficient to get the data admin_level by admin_level.

I see 2 issues I am currently blocked.

First, I get the borders of 4 countries in UK. Can this query be optimized? I also get the nodes (capital), but I am only interested in the borders?

[out:json];
rel(62149); //UK
map_to_area;
rel(area)[admin_level=4][boundary=administrative];
out geom;

Second, how do I get the children for a given country? I could increment the admin_level but some admin_levels are not used. Is it better to query for admin areas inside an area?

[out:json];
rel(58447); //England
map_to_area;
rel(area)[admin_level=5][boundary=administrative];
out geom;

This seems excessively slow and many queries. What can be optimized?

asked 11 Aug '21, 10:04

Seraphis's gravatar image

Seraphis
11112
accept rate: 0%


Unsure what you want your output to contain or what you want to use it for, but that would large amounts of data put a lot of strain on OP servers. If you're after full data https://osm-boundaries.com/ is recommended.

If you're after a list of names:

[out:csv(name,::id; false; ",")];
area(3600058447); //England
rel(area)[admin_level=5][boundary=administrative];
out tags;

3600000000 is the start number for relation's ids https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#By_element_id

RegEx can be used to search for different admin_levels in one call.

[out:csv(name,::id; false; ",")];
area(3600062149); //UK
rel(area)[admin_level~"[4,5]"][boundary=administrative];
out tags;
permanent link

answered 11 Aug '21, 13:26

DaveF's gravatar image

DaveF
3.3k8498133
accept rate: 16%

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
×228
×65
×54

question asked: 11 Aug '21, 10:04

question was seen: 2,306 times

last updated: 11 Aug '21, 13:26

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