[Qgis-developer] problem with feature request and updateFeature

Nathan Woodrow madmanwoo at gmail.com
Fri Mar 22 07:30:28 PDT 2013


Also Denis.  You can simplify the code a lot like this:

for f in vectorLayer.getFeatures( QgsFeatureRequest() ):
    f[field] = 1
    vectorLayer.updateFeature(f)


On Fri, Mar 22, 2013 at 11:10 PM, Denis Rouzaud <denis.rouzaud at gmail.com>wrote:

>  Yes exactly
>
>             f = QgsFeature()
>             iter = vectorLayer.getFeatures( QgsFeatureRequest() )
>             while iter.nextFeature( f ):
>                 print f.id()
>                 f.setAttribute( field, QVariant( 1 ) )
>                 vectorLayer.updateFeature( f )
>
> Prints only 1 id, commenting the last line prints all ids.
>
>
> On 03/22/2013 01:56 PM, Nathan Woodrow wrote:
>
> Do you mean your loop is exited when you call updateFeature?
>
>  Can you post your code.
>
>  - Nathan
>
>
>  On Fri, Mar 22, 2013 at 10:54 PM, Denis Rouzaud <denis.rouzaud at gmail.com>wrote:
>
>> Hi all,
>>
>> I am looping over features of a layer using new API (QgsFeatureRequest).
>> If I modify a feature and do: layer.updateFeature(f), my loop is broken.
>> Is this a normal behavior?
>>
>> What should I do if I want to modify features during the loop?
>>
>> Thanks
>>
>> Denis
>> _______________________________________________
>> 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/20130323/a590dc92/attachment.html>


More information about the Qgis-developer mailing list