I have two fields which I want to merge into a single field, thereby should one of the two to-be-merged fields be prioritized, meaning, if a value of one field is available take it instead of the other field.
I would like to have it like this:
field1 | field2 | resultField
-----------------------------
13 | NULL | 13
28 | 56 | 56
44 | NULL | 44
11 | 17 | 17
So the "field2"
should be prioritized in the resulting field.
I know, that I will need to create a new field, with the name relevant field name, so
vectorLyr = QgsVectorLayer('path_to_filed', 'layername', "ogr")
vectorLyr.isValid()
vpr = vectorLyr.dataProvider()
fieldnames = [resultField]
for name in fieldnames:
vpr.addAttributes([QgsField(name, QVariant.Double)])
vectorLyr.updateFields()
However, how can I now update the "resultfield"
with the values from the two fields?
pyqgis
was added to the backticks to tell it how to colourize it.