[QGIS-Developer] Get data from QgsFieldExpressionWidget (QGIS Master)

matteo matteo.ghetta at gmail.com
Mon Jun 26 22:52:44 PDT 2017


Hi Nyall,


> In QGIS 3.0 QgsVectorLayer::getValues will do what you want in a single call:
> 
> https://qgis.org/api/classQgsVectorLayer.html#ac8cfb12633ed536da73f42ebff095f99
> 
> That works for either a field:
> 
> layer.getValues('my_field')
> 
> or an expression:
> 
> layer.getValues('my_field * 2')

whoooooa I was not aware of that, thanks!

One further question, I tried it with the example field PH and the
expression PH > 7. This the outputs:

vl.getValues('PH')
([6.81, 6.78, 6.49, 6.72, 6.88, 7.68, 7.69, 7.38, 6.76, 6.84, 6.91,
6.74, 6.77, 6.73, 6.68, 6.94, 6.72], True)

vl.getValues('PH > 7')
([0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], True)

with the expression it seems the output is TRUE/FALSE. Any clue to
obtain also the attribute values?

Thanks again

Matteo


More information about the QGIS-Developer mailing list