There should be a method renameAttribute as part of QgsVectorLayer class.
You can do something like that:
layer = iface.activeLayer()
for field in layer.pendingFields():
if field.name() == 'old':
with edit(layer):
idx = layer.fieldNameIndex(field.name())
layer.renameAttribute(idx, 'new')
Good luck!
Marian
From: Qgis-user <[email protected]> On Behalf Of Ursula Heinze
Sent: June 1, 2021 5:26 AM
To: [email protected]
Subject: [EXT] [Qgis-user] Rename column
CAUTION: This email originated from outside of the organization. If you do not
recognize the sender or you are not certain the content is safe, then do not
click on any links or open any attachments.
AVERTISSEMENT : Ce courriel provient d’une source externe à l’organisation. Si
vous ne reconnaissez pas l’expéditeur ou si vous doutez de la sécurité du
contenu, ne cliquez sur aucun lien et n’ouvrez aucune pièce jointe.
Hello,
I have a little problem with the field calculator. I want to rename a column,
and I don´t find any way to do it.
Now I tried to copy the field values in a new column with the right name, and
am also not successful. Has anybody an idea for me, how to solve the problem?
Many thanks in advance!
Ursula Heinze
Gesendet von
Mail<https://urldefense.com/v3/__https:/go.microsoft.com/fwlink/?LinkId=550986__;!!P0kg3YazkQ!W94jRKLCVMrbhztEtw9jiDUPiECzoEscG5JxdIsa3_vpvGZuh4v0QGxdDJLtJD0Tmg$>
für Windows 10
________________________________
This electronic message, as well as any transmitted files included in the
electronic message, may contain privileged or confidential information and is
intended solely for the use of the individual(s) or entity to which it is
addressed. If you have received this electronic message in error please notify
the sender immediately and delete the electronic message. Any unauthorized
copying, disclosure or distribution of the electronic message is strictly
forbidden. NAV CANADA accepts no liability for any damage caused by any virus
and/or other malicious code transmitted by this electronic communication.
Le présent message électronique et tout fichier qui peut y être joint peuvent
contenir des renseignements privilégiés ou confidentiels destinés à l’usage
exclusif des personnes ou des organismes à qui ils s’adressent. Si vous avez
reçu ce message électronique par erreur, veuillez en informer l’expéditeur
immédiatement et supprimez le. Toute reproduction, divulgation ou distribution
du présent message électronique est strictement interdite. NAV CANADA n’assume
aucune responsabilité en cas de dommage causé par tout virus ou autre programme
malveillant transmis par ce message électronique.
_______________________________________________
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