1

I am trying to programmatically modify attributes for a vector layer, using calculated values currently stocked in a dictionary. Any pointers on where i'm going wrong?

my dictionary has the feature ID as keys and a value to be stocked in the corresponding feature. Mahalo in advance.

dict = {0.0: 27400.0, 1.0: 32900.0, 2.0: 42200.0, 3.0: 40600.0}

for feature in Gros_Feat:
    if caps & QgsVectorDataProvider.ChangeAttributeValues:
        attrs = {'SUM_Conso' : sumdict.values()[feature.id()]}
        grosLayer.dataProvider().changeAttributeValues({feature.id() : attrs})
        grosLayer.updateFields()
1

I don't know if it is a typographical error but the correct syntax for a Python dictionary is:

dict = {0.0: 27400.0, 1.0: 32900.0, 2.0: 42200.0, 3.0: 40600.0}
attrs = {'SUM_Conso' : dict.values}
print attrs
{'SUM_Conso': <built-in method values of dict object at 0x1002ba570>}
attrs = {'SUM_Conso' : dict.values()}
print attrs
{'SUM_Conso': [27400.0, 32900.0, 42200.0, 40600.0]}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.