Skip to content

Instantly share code, notes, and snippets.

@NathanW2
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NathanW2/8c981db9b31d00457cc0 to your computer and use it in GitHub Desktop.
Save NathanW2/8c981db9b31d00457cc0 to your computer and use it in GitHub Desktop.
def change_values(layer, **kwargs):
featuremap = {}
for feature, values in kwargs.iteritems():
attrs = {}
for field, value in values.iteritems():
index = layer.dataProvider().fieldNameIndex(field)
attrs[index] = value
featuremap[feature.id()] = attrs
return layer.dataProvider().changeAttributeValues(featuremap)
features = {feature1: {"field1": 1, "field2": 2},
feature2: {"field1": 1}}
change_values(layer, features)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment