<p><br>
<br></p>
<blockquote>
----Messaggio originale----<br>
Da: francescoboccacci@libero.it<br>
Data: 13/01/2013 18.03<br>
A: <giohappy@gmail.com><br>
Ogg: R: Re: [Qgis-developer] Commit delete features<br>
<br>
<p style="margin: 0px; padding: 0px;" mce_style="margin: 0px; padding: 0px;">Hi Giovanni,</p><p style="margin: 0px; padding: 0px;" mce_style="margin: 0px; padding: 0px;">this is my piece of code:</p><p style="margin: 0px; padding: 0px;" mce_style="margin: 0px; padding: 0px;"><br></p><p style="margin: 0px; padding: 0px;" mce_style="margin: 0px; padding: 0px;">provider = layer.dataProvider()<br><br> feat = QgsFeature()<br> allAttrs = provider.attributeIndexes()<br> provider.select(allAttrs)<br> caps = layer.dataProvider().capabilities()<br> fldDesc = provider.fieldNameIndex("values")<br> layer.startEditing()<br> <br> while provider.nextFeature( feat ):<br> <br> id = feat.id()<br> <br> attrs = feat.attributeMap()<br> for (k,attr) in attrs.iteritems():<br> if k == fldDesc:<br> if attr != 2.5:<br> <br> layer.dataProvider().deleteFeatures([ id ])<br> layer.commitChanges()<br> <br> <br> <br> layer.endEditCommand() </p><p style="margin: 0px; padding: 0px;" mce_style="margin: 0px; padding: 0px;"><br></p><p style="margin: 0px; padding: 0px;" mce_style="margin: 0px; padding: 0px;">but it doesn't work. Any suggestions?</p><p style="margin: 0px; padding: 0px;" mce_style="margin: 0px; padding: 0px;"><br></p><p style="margin: 0px; padding: 0px;" mce_style="margin: 0px; padding: 0px;">Thanks</p><p style="margin: 0px; padding: 0px;" mce_style="margin: 0px; padding: 0px;"><br></p><p style="margin: 0px; padding: 0px;" mce_style="margin: 0px; padding: 0px;">Francesco<br></p><p style="margin: 0px; padding: 0px;" mce_style="margin: 0px; padding: 0px;"><br></p><p style="margin: 0px; padding: 0px;" mce_style="margin: 0px; padding: 0px;"><br></p>
<blockquote>
----Messaggio originale----<br>
Da: giohappy@gmail.com<br>
Data: 13/01/2013 17.54<br>
A: <francescoboccacci@libero.it><br>
Ogg: Re: [Qgis-developer] Commit delete features<br>
<br>
<p dir="ltr">Have you called layer.startEditing()? </p>
<p dir="ltr">giovanni</p>
<p dir="ltr">Sent from Nexus</p>
<div class="gmail_quote">Il giorno 13/gen/2013 17:51, "<a href="mailto:francescoboccacci@libero.it" mce_href="mailto:francescoboccacci@libero.it">francescoboccacci@libero.it</a>" <<a href="mailto:francescoboccacci@libero.it" mce_href="mailto:francescoboccacci@libero.it">francescoboccacci@libero.it</a>> ha scritto:<br type="attribution">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex" mce_style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
i would like to delete the features in a shapefiles that haven't a specific<br>
field value. See below:<br>
<br>
provider = layer.dataProvider()<br>
<br>
feat = QgsFeature()<br>
allAttrs = provider.attributeIndexes()<br>
provider.select(allAttrs)<br>
caps = layer.dataProvider().capabilities()<br>
fldDesc = provider.fieldNameIndex("values") #values is field<br>
name<br>
while provider.nextFeature( feat ):<br>
id = <a href="http://feat.id" mce_href="http://feat.id" target="_blank">feat.id</a>()<br>
attrs = feat.attributeMap()<br>
for (k,attr) in attrs.iteritems():<br>
if k == fldDesc:<br>
if attr != 2.5:<br>
<br>
layer.dataProvider().deleteFeatures([ id ])<br>
layer.commitChanges()<br>
<br>
but it seems doesn't work.<br>
Any suggestion?<br>
<br>
Thanks<br>
<br>
Francesco<br>
<br>
<br>
_______________________________________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org" mce_href="mailto:Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" mce_href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote></div>
<br>
</blockquote><p><br></p><div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;" id="_mcePaste"> </div><br>
</blockquote><p><br></p>