I have a stand-alone PyQGis program and I need to periodically access the selected features of some vector layers. But I noticed that there seems to be no python wrapper for the 'selectedFeatureIds' or the 'getSelectedFeatures' methods of QgsVectorLayer class. There is a python wrapper for the 'selectedFeatures' function, but the documentation says that it actually makes copies of the selected features, which I don't want, all I want is to be able to iterate through selected features without duplicating anything. The QGis core is from QGis 2.12 (lyon) and PyQt4.

So this means there is no good way of getting access to the selected features in a layer in pyqgis apps.

1 Answer 1


After looking at the selectedFeatures C++ source code, it seems that it returns the iterator over selected features (doesn't look like deep copy is done, would like to have confirmation about this though). I just tried this call and it indeed returned a list of the selected features. So, I would say this to be the solution to this issue for now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.