I have two layers where different columns exist. I want to copy a layer column into antoher layer column programatically. I have done the below code so far:
layerNameValueSet = "PLATFORM"
#columnNameSet where to value add
columnNameSet = "ZONEID"
#LayerName Where to copy column values
layerNameValueGet= "LOT"
#Above layer's[layerNameValueGet] cloumn name from value will be get for copy in layerNameValueSet
columnNameGet = "ZONEID"
#Getting layer of specifc name
layerNameValueSetObj = QgsMapLayerRegistry.instance().mapLayersByName(layerNameValueSet)[0];
layerNameValueGetObj = QgsMapLayerRegistry.instance().mapLayersByName(layerNameValueGet)[0];
fieldIndexToSet = layerNameValueSetObj.fieldNameIndex(columnNameSet)
fieldIndexToGet = layerNameValueGetObj.fieldNameIndex(columnNameGet)
for getFeature in layerNameValueGetObj.getFeatures():
#this logic is not correct /taking too much time hanging
for setFeature in layerNameValueSetObj.getFeatures():
if(getFeature.id() == setFeature.id()):
layerNameValueSetObj.startEditing()
updateValue = getFeature[columnNameGet]
layerNameValueSetObj.changeAttributeValue(setFeature.id(), fieldIndexToSet, updateValue)
layerNameValueSetObj.commitChanges()