Nesting models

As we previously covered, when a model is saved to the Models folder, it will appear in the Models category of the Processing Toolbox panel. What we didn't mention earlier was that it will also appear in the Algorithms tab of the Processing modeler window. This means that a previously written model can be used as an algorithm in another model.

Note

Models won't appear as algorithms if some of their component algorithms are not available. This can happen if an algorithm provider is deactivated in Providers, and you can find this by navigating to Processing | Options. For example, if you have used a SAGA tool in a model but have subsequently deactivated SAGA tools, that model will not be available. As long as all the algorithms in a model are visible in the Processing Toolbox panel, a model will be available as an algorithm.

To demonstrate this feature, we will build on the model that we used in the previous section. The model clipped elevation data by watershed boundaries. With a DEM, you can generate a metric called Topographic Wetness Index (TWI). The QGIS sample model (TWI_from_DEM.model) shown in the following screenshot takes one input, a DEM. From this input, it generates slope and catchment areas. These then feed into the Topographic Wetness index algorithm:

Nesting models

First, we will create a new copy of the DEMs Clipped to Watersheds model using the Save as button. We will name this new model file TWI_for_watersheds.model. The TWI From DEM model is located in the Algorithms tab and is added as an algorithm to our new model. (Remember that models need to be saved to the Models folder to appear as algorithms.) You will notice that the model icon in the modeler canvas for the TWI From DEM algorithm identifies the algorithm as a model:

Nesting models

The DEM will be clipped to the watersheds layer, and the clipped DEM will be the input to the TWI From DEM algorithm. This will create one output, a TWI raster covering the watersheds. However, if the Iterate over this layer setting is used, the DEM will be clipped to each of the 21 watersheds and the TWI will be calculated for each. This will use both a nested model and the iterate feature in the same model:

Nesting models

The following figure shows the output of the TWI for Individual Watersheds nested model using the iterator feature:

Nesting models

Note

As of version QGIS 2.6, you can have as many levels of nested models as you wish. There is no limit!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.174.168