I have two layers, pipes and intersect layers. Both layers have an id, score column but intersect layer does not have all the ids present in pipes. So I am trying to check if the id present in pipes exists in intersect, if yes then copy intersect's score to pipe's score else leave it blank and continue. But the code neither gives an error nor does it make the changes in the attribute table of the pipe layer. Am I missing something? The code is as follows:
pipe_feat = selectedLayer.getFeatures() #pipes layer
field4 = selectedLayer.fields().indexFromName(fid1) #id column is referenced
selectedLayer.startEditing()
featLayer = layer.getFeatures() #intersect layer
field3 = layer.fields().indexFromName('PIPEID')
for feat in pipe_feat:
for f in featLayer:
if feat[field4]==f[field3]:
feat['SewerScore'] = f['Score']
selectedLayer.updateFeature(feat)
else:
continue
selectedLayer.commitChanges()
I have also tried this method: But even this does not work.
id_score={}
for f in featLayer:
id_score[f[field3]] = f['Score']
for feat in pipe_feat:
for key,value in id_score.items():
if key == feat[field4] :
feat['SewerScore'] = id_score.get[key]
layer.updateFeature(f)
selectedLayer.updateFeature(feat)
else:
continue