[QGIS-Developer] QgsExpression python pattern
Chris Crook
ccrook at linz.govt.nz
Wed Jan 31 12:11:52 PST 2018
Chris Crook wrote
> I am updating some plugins which use QgsExpression, and I'm wondering
> about the best way to use expressions in QGIS3. It in the past I used a
> pattern like:
>
> exp=QgsExpression(expressionText)
> exp.prepare(fields)
> request=QgsFeatureRequest()
> request.setSubsetOfAttributes( expression.referencedColumns(), fields )
> for feat in layer.getFeatures(request)
> value=expression.evaluate(feat)
>
> However with QGIS3 this has clearly changed! QgsExpression is not
> included in the QGIS3 API https://qgis.org/api/annotated.html. The
> prepare and referencedColumns are no longer defined. I did have a look at
> the C++ code for QgsExpression, but I find I'm still looking for guidance.
>
> I've searched the QEP issues been able to locate a QEP, or other
> documentation. Can anyone point me to some documentation or provide an
> example of current best practice please.
Correction: prepare and referencedColumns are still present, prepare takes
QgsExpressionContext rather than fields. So I think the pattern is very
little changed
--
Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-Developer-f4099106.html
More information about the QGIS-Developer
mailing list