I'm looking for a solution to select islands (non-black polygons) in polygon A (black).
I think, in PostGIS ST_ContainsProperly()
will do this task. But I'm looking for an equivalent solution in PyQGIS.
The function shall only return True
when checking the green polygon. Checking the grey MultiPolygon shall return False
, because it is partially outside and the red polygon False
because it touches the border
I tried the code from this thread
path_1 = r"C:\temp\test_poly.shp"
path_2 = r"C:\temp\test_poly_umr.shp"
layerB = QgsVectorLayer(path_1, "layerB", "ogr")
layerA = QgsVectorLayer(path_2, "layerA", "ogr")
if layerA.isValid():
QgsProject.instance().addMapLayer(layerA)
if layerB.isValid():
QgsProject.instance().addMapLayer(layerB)
island = False
for bF in layerB.getFeatures():
for aF in layerA.getFeatures():
if aF.geometry().intersects(bF.geometry()):
if bF.geometry().contains(aF.geometry()):
island = True
print(bF[0], ' ', island)
island = False
... but it returns island=True
for Polzgon #5 instead of polygon #3 (as expected)