Wednesday 2 October 2019

qgis - Is it possible to programmatically add calculated fields?


In the Memory provider described in PyQGIS Cookbook or in question How to create a new empty vector layer programmatically? I can see how to create a vector layer programmatically using standard fields (String, Int, Double).


with PyQGIS/QGIS 1.8.0, is it possible to programmatically add calculated fields like the ones defined using the GUI field calculator? After some reading about QgsExpression I'm thinking in something like this:


exp = QgsExpression('Column * 3')
pr.addAttributes( [ QgsField( "fieldName", QVariant.Expression, exp ) ] )



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...