QGIS – Selecting Polygons Completely Inside Another Layer Without Common Vertices or Edges

qgisselect-by-location

Backgound:

At 3.34.2, consider a scenario involving two polygon layers, as shown in the diagram below. The task is to select by location polygons from Layer A, compared to Layer B, that return only polygon #3.

Polygon #3 is unique because it is completely within a Layer B polygon, yet it shares no vertices or edges with that polygon.

I've tested every checkbox option in the Select by Location tool. None of them will return just polygon #3. For example, the "are within" option selects all three polygons.

I've also experimented with the "overlay" expressions, such as overlay_within('Layer_B'), but without success.

I also tried the "Select Within" plugin, but it was not able to select just Polygon #3.

Question:

How to select polygons from one layer that are completely inside polygons from another layer, yet have no vertices or edges in common.

Bonus points for techniques that would select Polygon #1, as well as Polygon #2!

enter image description here

Best Answer

You could add an extra clause to check if the polygon from Layer A intersects the boundary (a line) of Layer B.

overlay_within('Layer B') 
and not 
intersects(@geometry, boundary(aggregate('Layer B', 'collect', @geometry)))