I have a shapefile with only one field "DN". I would like to delete all features which does not have specific value of the field. Let's say the "DN" can be 1,2 or 3.
So far I was able to find out how to select Features and how to delete feature, but I did not succeed to combine them. Let's say I want only features with "DN" = 3 to remain:
Selection of the Features found here : Filter features based on their attributes using Python, however, I do not know if it does what it is supposed to do since I did not find the way how to check what is inside.
select = layer.getFeatures(QgsFeatureRequest().setFilterExpression(u'"DN"!=3'))
delete features found in the PyQGIS Developer Cookbook
res = Ilayer.dataProvider().deleteFeatures()
As far as I know, the deleteFeatures() requires "ID"s of the features, but I have no idea how to get them from from select which is QgsFeatureIterator.