drolbr / Overpass-API

A database engine to query the OpenStreetMap data.
http://overpass-api.de
GNU Affero General Public License v3.0
692 stars 90 forks source link

Adminstrative relation not found inside its parent area #669

Closed Szetty closed 2 years ago

Szetty commented 2 years ago

Hello, we have a query, where we want to find all administrative relations inside another administrative relation. I have used a query where I search the parent relation by id, map it to an area, and then search for all relations that are administrative inside this area. This query has been working for 99% of the cases, but I have found one exception: https://www.openstreetmap.org/relation/2785126. For some reason I cannot find this relation inside its administrative relation. I have two examples:

  1. https://postimg.cc/ph8gCz5J with query "[out:json];area(3602955436);node(area);out;"
  2. https://postimg.cc/zL4sT0vf with query "[out:json];area(3602955436);rel(area)[admin_level];way(r);node(w);out;"

In 1 I am querying for all the nodes inside the parent area, and as we can see all nodes are returned. In 2 I am querying for all the adminstrative relations inside the parent area and then for their ways and nodes of the ways, which will give me the boundaries of the relations. As you can see only 2/3 relations are outlined by the nodes.

Any idea what might be the problem ?

mmd-osm commented 2 years ago

By construction, the outer boundary of your area is not part of the area itself. If the relation shares all ways with the relation-based area and doesn't have any nodes inside the area, it won't be considered to be inside the relation.

Szetty commented 2 years ago

what do you mean by doesn't have any nodes inside the area ? on the first image you can see that there are a ton of points even inside the area that are also part of the parent area

mmd-osm commented 2 years ago

What I mean is that none of the relations you're looking for has any node members (such as an admin_centre), or any way members, which are not exactly matching your existing area boundary ways. Existing relations have exactly the same ways as relation 2955436, hence, there's nothing "inside" of the area.

The nodes on the first screenshot are irrelevant here, because they're not members of an admin relation.

Szetty commented 2 years ago

Thank you for your answer, I think I understand, will take some time to understand it fully and will return. Do you have any solution (maybe change the query, or maybe change sth in Overpass or OSM) ?

Szetty commented 2 years ago

I have taken a deeper look, compared relation/1103630 with my relation (2785126). So if I understand correctly:

  1. 2785126 is not part of 2955436 because there is NO way/node that is only part of 2785126 (and not part of 2955436)
  2. 1103630 is part of 2955436 because it has two ways (207174744 and 207174746) that are NOT part of 2955436
drolbr commented 2 years ago

Relation 2785126 is not inside the area spanned by relation 2955436 because there is no point of relation 2785126 that is properly inside relation 2955436.

Overpass API treats relation 2785126 based on its way and node members and is not aware that it is a closed area. As such relation 2785126 is relative to relation 2955436 similar to relation 1683644. Both share a part of their boundary with relation 2785126 but have no points inside. For sure, relation 1683644 is not expected to be in the result.

The source of the problem is that there is no proper area type in the OSM data model. On top of that, there is no area-in-area operator in Overpass API at the moment.

Szetty commented 2 years ago

Would the problem be solved if I add an admin_centre (for example the node 240044253) in 2785126 ?

drolbr commented 2 years ago

For this relation, yes.

Szetty commented 2 years ago

will try that, thank you for your help :)

mmd-osm commented 2 years ago

Relevant changeset: https://www.openstreetmap.org/changeset/122412808