我设置任务的方式是创建一个自定义脚本,该脚本比建模器具有更大的灵活性,但仍然可以为其用户提供类似的界面。您可以通过以下方式创建一个:
处理工具箱>脚本>工具>创建新脚本
然后复制/粘贴以下脚本并将其保存到中C:/Users/You/.qgis2/processing/scripts
。
下面的脚本试图模拟您的模型的作用。该脚本不是最终的解决方案(特别是因为我用于定位工具的“ 相交”和“ 连接”属性的参数可能与您定义的参数不同),但希望您可以将其用作模板来扩展和改进脚本以适应您的需求。要运行它,只需在保存后从“ 处理工具箱”中选择它即可。
我认为脚本可以满足您的要求:
##Example model=name
##Order1=vector
##Order2=vector
##Order3=optional vector
##Order4=optional vector
##Order5=optional vector
##Watershed=vector
##Order2_Wshed=output vector
##Order3_Wshed=output vector
##Order4_Wshed=output vector
##Order5_Wshed=output vector
order1 = processing.getObject(Order1)
order2 = processing.getObject(Order2)
order3 = processing.getObject(Order3)
order4 = processing.getObject(Order4)
order5 = processing.getObject(Order5)
watershed = processing.getObject(Watershed)
if Order3 is None:
print 'Processing Order1 and Order2'
else:
print 'Processing Order1, Order2 and Order3'
if Order4 is not None:
print 'Processing Order1, Order2, Order3 and Order4'
if Order5 is not None:
print 'Processing Order1, Order2, Order3, Order4 and Order5'
output_1a = processing.runalg("qgis:intersection", order1, watershed, None)
output_1b = processing.runalg("qgis:joinattributesbylocation", output_1a['OUTPUT'], watershed, u'intersects', 0, 0, '', 0, None)
output_2a = processing.runalg("qgis:intersection", order2, watershed, None)
output_2b = processing.runalg("qgis:joinattributesbylocation", output_2a['OUTPUT'], output_1b['OUTPUT'], u'intersects', 0, 0, '', 0, Order2_Wshed)
if Order3 is None:
pass
else:
output_3a = processing.runalg("qgis:intersection", order3, watershed, None)
output_3b = processing.runalg("qgis:joinattributesbylocation", output_3a['OUTPUT'], output_2b['OUTPUT'], u'intersects', 0, 0, '', 0, Order3_Wshed)
if Order4 is None:
pass
else:
output_4a = processing.runalg("qgis:intersection", order4, watershed, None)
output_4b = processing.runalg("qgis:joinattributesbylocation", output_4a['OUTPUT'], output_3b['OUTPUT'], u'intersects', 0, 0, '', 0, Order4_Wshed)
if Order5 is None:
pass
else:
output_5a = processing.runalg("qgis:intersection", order5, watershed, None)
output_5b = processing.runalg("qgis:joinattributesbylocation", output_5a['OUTPUT'], output_4b['OUTPUT'], u'intersects', 0, 1, 'sum, mean', 0, Order5_Wshed)
以下是运行脚本时界面的屏幕截图(外观应类似于运行模型时的界面):
几件事要注意:
我使用了QGIS 2.12.3(带有处理插件版本2.12.2)。