Answers:
从以下位置创建一个新脚本:
Processing Toolbox > Scripts > Tools > Create new script
使用如下所示的内容:
##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()
将脚本保存在C:/Users/You/.qgis2/processing/scripts/
目录中。然后,您应该能够在建模器中调用此脚本。