Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSM Overpass: get parent polygon

Is it possible to get the parent polygon of a relation, way or node?

For example: This beach is inside this island. And the Island is inside a National Park. And the National park is inside a country, etc.

Can I get the closest surrounding polygon out of OSM with the Overpass Api?

Example, this beach is inside the island:

enter image description here

like image 272
NLAnaconda Avatar asked Feb 16 '26 20:02

NLAnaconda


1 Answers

Found the answer.

This query will get all the polygons it lies in. From the smallest to the largest (country). Where "317086850" is the Osm id. (Test it here)

way(317086850);
>;
is_in;
out;

But this is not sufficient. If (for example) a beach lies on an island, but the polygon overlaps the island border for a tiny bit. The query above will not get it. So I use this query to get all border shares. Which will come up with the island. (Test it here)

way(317086850)->.boundaryways;
way[natural](around.boundaryways:0);
(._; - way.boundaryways[natural];);
(._; - way.boundaryways[place];);
out geom;
like image 108
NLAnaconda Avatar answered Feb 21 '26 16:02

NLAnaconda