NLAnaconda
NLAnaconda

Reputation: 1595

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

Upvotes: 2

Views: 1162

Answers (1)

NLAnaconda
NLAnaconda

Reputation: 1595

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;

Upvotes: 2

Related Questions