[Qgis-developer] Commit delete features

francescoboccacci at libero.it francescoboccacci at libero.it
Sun Jan 13 08:51:47 PST 2013


Hi all,
i would like to delete the features in a shapefiles that haven't a specific 
field value. See below:

              provider = layer.dataProvider()

              feat = QgsFeature()
              allAttrs = provider.attributeIndexes()
              provider.select(allAttrs)
              caps = layer.dataProvider().capabilities()
              fldDesc = provider.fieldNameIndex("values") #values is field 
name
              while provider.nextFeature( feat ):
                id = feat.id()
                attrs = feat.attributeMap()
                for (k,attr) in attrs.iteritems():
                    if k == fldDesc:
                        if attr != 2.5:
                          
                            layer.dataProvider().deleteFeatures([ id ])
                            layer.commitChanges()
                          
but it seems doesn't work.
Any suggestion?

Thanks

Francesco




More information about the Qgis-developer mailing list