[Qgis-user] pyQGIS - set attributes by expression

Wouter Impens wouter.impens at gmail.com
Wed Feb 6 00:14:38 PST 2019


Hi Nyall,

It is indeed a QgsExpression object. I 'm able to use it in the field
calculator so it should work...


Op di 5 feb. 2019 22:25 schreef Nyall Dawson <nyall.dawson at gmail.com>:

> On Wed, 6 Feb 2019 at 00:37, Wouter Impens <wouter.impens at gmail.com>
> wrote:
> >
> > 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
>
> What's "an_expr" here? Is it a QgsExpression object?
>
> Nyall
>
> >          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
> > _______________________________________________
> > Qgis-user mailing list
> > Qgis-user at lists.osgeo.org
> > List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20190206/434931e1/attachment.html>


More information about the Qgis-user mailing list