I am trying to create a new attribute field "FromNode"
in a layer that contains string with an integer.
EXAMPLE: name1
, name2
, name3
, name4
, ...
till the end of the table.
I got the solution by doing manually in QGIS Field Calculator.
concat('name', "id")
The manual procedure is tedious due to multiple layers.
Is there a way to automatically do this using PyQGIS or even SQL query in Virtual layer
approach?
Attempt in PyQGIS
Problem: It only creates empty 'String' field. I want to update the field with string "Name"
+ increment of "integer 1"
in each row. For instance, name1, name2, name3, ...
layer = iface.activeLayer()
myField = QgsField('FromNode', QVariant.String,'character', 200)
layer.dataProvider().addAttributes([myField])
layer.updateFields()