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

francescoboccacci at libero.it francescoboccacci at libero.it
Sun Jan 13 09:27:30 PST 2013


Hi all,solved. This is the right code:
              provider = layer.dataProvider()
              feat = QgsFeature()
              allAttrs = provider.attributeIndexes()
              provider.select(allAttrs)
              caps = layer.dataProvider().capabilities()
              fldDesc = provider.fieldNameIndex("values")
              layer.startEditing()
              arrayid=[]
              while provider.nextFeature( feat ):
                
                id = feat.id()
        
                attrs = feat.attributeMap()
                for (k,attr) in attrs.iteritems():
                    if k == fldDesc:
                        if attr != 2.5:
                            arrayid.append(id)
                            
              layer.dataProvider().deleteFeatures(arrayid)       
              layer.commitChanges()              
thanks.l
Francesco



----Messaggio originale----

Da: francescoboccacci at libero.it

Data: 13/01/2013 18.03

A: <qgis-developer at lists.osgeo.org>

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









----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/2cbd1378/attachment-0001.html>


More information about the Qgis-developer mailing list