Skip to content

Instantly share code, notes, and snippets.

@NathanW2
Created October 9, 2013 13:45
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/6901558 to your computer and use it in GitHub Desktop.
Save NathanW2/6901558 to your computer and use it in GitHub Desktop.
import uuid
fieldname = 'UUID' # set the name of your field to update
layer = qgis.utils.iface.activeLayer() # get the active layer from the TOC
layer.startEditing() # start editing
iter = layer.getFeatures() # get all features from the layer
for feat in iter: # iterate over features
feat[fieldname] = str(uuid.uuid4()) #fill field with GUID
layer.updateFeature(feat)
layer.commitChanges() # save edits to the layer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment