[Qgis-user] pyQGIS - set attributes by expression

Wouter Impens wouter.impens at gmail.com
Tue Feb 5 06:36:10 PST 2019


Hi,

Hope anyone can help me with this:

I'm trying to iterate over the fields of a vector layer (using the index)
and fill in the values by an expression

 my_features = a_layer.getFeatures()
    for a_feat in my_features:
        mijn_index = a_feat.fieldNameIndex('perc_nr')
        value = an_expr
         a_feat.setAttribute(mijn_index, value)

    a_layer.commitChanges()

I don't get an error but nothing is filled in. I evaluated the expression
and it's true. It also works in the field calculator.

Anyone an idea?


Kind regards
Wouter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20190205/364c8df4/attachment.html>


More information about the Qgis-user mailing list