Sunday, 15 March 2015

python - Set layer in edit mode in QGIS processing


Set a layer editable through the Python console works fine here (QGIS 2.18.4):


layer=iface.activeLayer()
if not layer.isEditable():
qgis.utils.iface.actionToggleEditing().trigger()

But I do not know how to set a input layer editable in a QGIS processing script:


##Input_layer=vector

# ...
inlayer = processing.getObject(Input_layer)
if not inlayer.isEditable():
#???

Can anybody help me with this?



Answer



You can use QgsVectorLayer.startEditing().
Then once your edits are complete you can either commitChanges() or rollBack() as approriate


##Input_layer=vector

# ...
inlayer = processing.getObject(Input_layer)
if not inlayer.isEditable():
inlayer.startEditing()
# ...
inlayer.commitChanges()

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...