I want to check a vector file if there is a column "Source".
If yes, nothing to do. If there is no column "Source" it should be created and filled up with '0'.
Is this possible to do via the modeler?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
Create a new script from:
Processing Toolbox > Scripts > Tools > Create new script
Use something like the following:
##Example=name ##Layer=vector from qgis.core import QgsField from PyQt4.QtCore import QVariant layer = processing.getObject(Layer) idx = layer.fieldNameIndex('Source') if idx != -1: pass else: layer.startEditing() layer.dataProvider().addAttributes( [ QgsField("Source", QVariant.Int) ] ) layer.updateFields() for feat in layer.getFeatures(): layer.changeAttributeValue(feat.id(), layer.fieldNameIndex('Source'), '0') layer.commitChanges()
Save the script in your
C:/Users/You/.qgis2/processing/scripts/ directory. Then you should be able to call this script in your modeler.