I'm trying to select and zoom on selected features on standalone QGis application. Selection seems to work, console shows me list of selected items and they are exactly I expected.
ids = []
for f in kt.getFeatures():
if f['KatastriNumber']==k_n:
ids.append(f.id)
print f['eraldus']
kt.setSelectedFeatures(ids)
But zooming to selection does not work. I have tried many code samples i found from internet. None of them doesnt zoom to selected. Can only zoom to entire layer with:
canvas.setExtent(kt.extent())
I tried to make a box with command:
box = kt.boundingBoxOfSelected()
canvas.setExtent(box)
This gives no result.Then I tried with command
canvas.zoomToSelected(kt)
also no result. How to tell app that some features from layer are selected?
canvas.zoomToSelected()
(with no argument) already? Also, it should bef.id()
(with parenthesis) to properly call the id method. You can checkck.selectedFeatureCount()
to make sure you have selected features. This post tells you how to use expressions to select features and then zoom to the selection: gis.stackexchange.com/questions/91011/…