There is a big difference between "areas inside areas" and "boundaries inside boundaries". The first issue is much more general and I will try to answer that one.
Assume an open simple 2D area is a set of all points strictly inside an outer/enclosing border polygon and strictly outside and arbitrary number (including zero) of inner/excluding/hole border polygons. A closed area, besides its inner points, contains all border points as well. You can prove that any complex area, or a set of complex areas, has a perfect coverage of disjunctive simple areas. Therefore, hereafter we consider only simple closed areas.
We can say/define that an area Ab is inside another area Aa if, and only if, any inner or border point of Ab is an inner or border point of Aa. Now the question is how to check this condition efficiently? Here are some hints and suggestions:
Any math/GIS library should contain (almost guaranteed) a function point-polygon(…) that returns one of the values for a given point and polygon: the point is strictly inside, outside or it is exactly on the polygon. Also, the library should contain a function polygon-in-polygon(…) that returns yes or no for two given polygons Pb and Pa. If not, you can make it easily using the point-polygon(…) function. Namely, we can say/define that Pb is inside Pa if any point of Pb is not strictly outside Pa. In addition, you can prove that Pb is inside Pa if, and only if, any of the node points of Pb is not strictly outside Pa and none of the node points of Pa is strictly inside Pb.
Now, using the polygon-in-polygon(…) function you can efficiently check whether and area Ab is inside another area Aa. Namely, you can prove that a given area Ab is inside a given area Aa if, and only if:
1. The outer border polygon Pb of area Ab is inside the outer border polygon Pa of area Aa; and
2. Any hole polygon Ha of area Aa is either inside or outside the outer polygon Pb of area Ab. If inside, then Ha must be inside of a hole polygon Hb of area Ab.
Good luck and enjoy the OSM.
answered 26 Feb '16, 20:44

sanser
695●38●39●55
accept rate: 5%
To convert a way or relation back to an area (if available), use the
map_to_area
statement.