Modeler字段计算器中的条件


Answers:


10
  1. 从以下位置创建一个新脚本:

    Processing Toolbox > Scripts > Tools > Create new script
    
  2. 使用如下所示的内容:

    ##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()
    
  3. 将脚本保存在C:/Users/You/.qgis2/processing/scripts/目录中。然后,您应该能够在建模器中调用此脚本。


1
@Pimpel-非常欢迎,很高兴能为您提供帮助=)
约瑟夫
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.