Hi
I would like to add a virtual field to a PostGIS vector layer with
PyQGIS with standalone scripts
(https://docs.qgis.org/3.34/en/docs/pyqgis_developer_cookbook/intro.html#python-applications)
All examples I have found so far with google, chatgpt4 and JetBrains AI
Assistant gave me solutions that do not work. They only work in the
Python Console inside QGIS.
Does anybody know of a solution that works with PyQGIS with standalone
scripts?
See below what I have tried so far in different variations.
Thanks for any help
Roland
Example created by chatgpt:
...
field_name = "virtual_field"
expression = '"attribute_name" * 2' # Example expression
# Create and add the virtual field
layer.startEditing()
layer.addExpressionField(expression, QgsField(field_name, QVariant.Double))
layer.commitChanges()
...
_______________________________________________
QGIS-User mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user