I'm trying to find features (polygons) that intersect a QgsRectangle
but are not equal to themselves. In the image below, I have a bounding box around a feature. I'd like to see what other polygons intersect that bounding box. This is the part I'm stuck on. If features are found (usually two but maybe more or less), I'd like to create a convex hull of all those features.
My code of what I have thus far is below.
layer = iface.activeLayer()
features = layer.getFeatures()
feat = QgsFeature()
ok = features.nextFeature(feat)
p1 = None
p2 = None
while ok:
p1 = feat.geometry()
print('p1 is --')
print(p1)
rect = p1.boundingBox()
search_area = QgsRectangle(
rect.xMinimum() - 1,
rect.yMinimum() - 1,
rect.xMaximum() + 1,
rect.yMaximum() + 1)
print(p1.intersects(search_area))
ok = features.nextFeature(feat)
Update: So Im trying to achieve the following - only create a convex hull of what the rectangle intersects with.
From @BERA excellent piece of work, I get the following back which is close but not exactly what I want: