I'm researching the shortest distance between two selected polygons among the number of polygons in a shapefile using PyQGIS. Coding as follows>
layer = iface.activeLayer()
sFeat1 = layer.getFeature(0)
tFeat1 = layer.getFeature(1)
sGeom1 = sFeat1.geometry()
tGeom1 = tFeat1.geometry()
dist_m1 = sGeom1.distance(tGeom1)
print(dist_m1)
The problem is that it always returns the same distance, despite the selected polygon. What is wrong with my code?