The way I would set your task up would be to create a custom script which provides greater flexibility than the modeler but can still provide a similar interface to its users. You can create one from:
Processing Toolbox > Scripts > Tools > Create new script
Then copy/paste the script below and save it into C:/Users/You/.qgis2/processing/scripts
.
The script below tries to emulate what your model does. The script is not a final solution (especially since the paramaters I used for the Intersection and Join attribute by location tools may differ from what you defined) but hopefully you could use it as a template to expand and improve upon the script to suit your needs. To run it, simply select it from the Processing Toolbox after it has been saved.
I think the script does what you asked:
First two orders are mandatory so will be processed.
IF
statements are used to ensure that any succeeding orders will only get processed if the correct one precedes it (e.g. order4 will only run if order3 has been selected).
In addition, messages are printed in the Python Console showing which orders are being processed.
##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)
Below is a screenshot of the interface when running the script (which should look similar to when you run your model):
Few things to note:
Red box contain mandatory parameters
Green box contains optional parameters
Blue box contains mandatory parameter
Black box contains optional parameters to output results. The script will only output layers if the associated order is selected (e.g. if the input for order5 is not selected but the output for it is, an error will occur). Therefore, the user must select the inputs and the relevant outputs. This wasn't intentional but personally I think it's a good way to force the user to check the parameters carefully.
I used QGIS 2.12.3 (with Processing plugin version 2.12.2).
Best Answer
I found a work around which give me satisfactory results. It seems a bit long winded though, so if anyone can help me to improve this workflow, I'd appreciate it.
Give the non-spatial table of inspections an arbitrary geometry using the 'points layer from table' tool and the id field
Since the output from 1 has a geometry and is stored as a temporary shp I can now use the 'execute sql' tool on the output using
SELECT * FROM "output" ORDER BY date DESC
Now use the 'join attributes' table tool to join the ordered inspections to the gullies. Since this tool picks up the first matching record from the inspections table the most recent will be joined.
Hope this helps someone