[Qgis-developer] I: Re: Commit delete features

francescoboccacci at libero.it francescoboccacci at libero.it
Sun Jan 13 09:03:48 PST 2013







----Messaggio originale----

Da: francescoboccacci at libero.it

Data: 13/01/2013 18.03

A: <giohappy at gmail.com>

Ogg: R: Re: [Qgis-developer] Commit delete features



Hi Giovanni,this is my piece of code:
provider = layer.dataProvider()

              feat = QgsFeature()
              allAttrs = provider.attributeIndexes()
              provider.select(allAttrs)
              caps = layer.dataProvider().capabilities()
              fldDesc = provider.fieldNameIndex("values")
              layer.startEditing()
              
              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()
                            
                         
                        
                layer.endEditCommand()     
but it doesn't work. Any suggestions?
Thanks
Francesco




----Messaggio originale----

Da: giohappy at gmail.com

Data: 13/01/2013 17.54

A: <francescoboccacci at libero.it>

Ogg: Re: [Qgis-developer] Commit delete features



Have you called layer.startEditing()? 
giovanni
Sent from Nexus
Il giorno 13/gen/2013 17:51, "francescoboccacci at libero.it" <francescoboccacci at libero.it> ha scritto:
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





_______________________________________________

Qgis-developer mailing list

Qgis-developer at lists.osgeo.org

http://lists.osgeo.org/mailman/listinfo/qgis-developer






 



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20130113/bd5299ab/attachment.html>


More information about the Qgis-developer mailing list