In QGIS 3.10, i want to calculate multiple fields at once on more than 10 similar layers. I now i can do it manually, but I'm looking for an automatic way.
I need something like this:
"nomrue" should be filled with "potable_nomrue" And
"debut" should be filled with "potable_debut" And
"fin" should be filled with "potable_fin" And
"seqsegment" should be filled with "potable_seqsegment" And
"idnoeuddebut" should be filled with "potable_idnoeuddebut" And
"idnoeudfin" should be filled with "potable_idnoeudfin" And
"vocation" should be filled with "potable_vocation" And
And so on... And i need to repeat the operation on multiple layers.
I found some Python code, but i don't understand how to use Python...
Ihave:
lyr = iface.activeLayer()
with edit(lyr):
for f in lyr.getFeatures():
f['nomrue'] = f['potable_nomrue']
f['debut'] = f['potable_debut']
f['fin'] = f['potable_fin']
f['seqsegment'] = f['potable_seqsegment']
f['idnoeuddebut'] = f['potable_idnoeuddebut']
f['idnoeudfin'] = f['potable_idnoeudfin']
f['vocation'] = f['potable_vocation']
f['anneerehab'] = f['potable_anneerehab']
lyr.updateFeature(f)
But there's an error... What's wrong?
"Field 6" should be filled with "z_Field6"
you mean field 6 should be filled with the value of z_Field6?for lyr = iface.activeLayer()
must belyr = iface.activeLayer()
. But there is also a false indentation on your last line andi
ist not defined.f['nomrue'.format(i)]
is lacking where to place the i (for example'nomrue{}'.format(i)
fornomrue1
).