[GIS] How to determine if a Polygon is inside another Polygon’s hole

de-9imgeometrygis-principle

Given two valid polygons P and Q, what's the cheapest / fastest way to determine:

If polygon Q is inside one of polygon P's holes (interior rings), or vice versa. (see illustration below)

To the best of my knowledge, the DE-9IM predicates don't directly help here, since the polygons are disjoint (FF2FF1212) according to the matrix, so checks for containment, intersection, crossing, and within aren't useful.
The best I've come up with is:

  • check whether the polygons intersect
    • if they don't, construct polygons from their bounding boxes, then check whether P_bbox contains Q_bbox, or vice versa.
    • One polygon's bounding box will always have to be strictly smaller than the other.

But I'm wondering whether this might catch some other arrangement that I haven't thought of.

enter image description here

Best Answer

Since you are dealing with holes, you could replace such polygons with a filled version. If the polygon has an inner ring, take the outter ring and create a new temporary polygon, then check if it contains others. If yes, using the original polygon, check that it doesn't intersect the smaller one