Tutorial: Automate Stream & Catchment Delineation using the Graphical Modeller
Site: | OpenCourseWare for GIS |
Course: | QGIS Advanced Tutorials |
Book: | Tutorial: Automate Stream & Catchment Delineation using the Graphical Modeller |
Printed by: | Guest user |
Date: | Saturday, 21 December 2024, 2:57 PM |
1. Introduction
QGIS has some great ways to automate your processes. You can use PyQGIS to build scripts. But if you're looking for a more graphical way, the Graphical Modeller is a great way to automate your processes using the tools from the Processing Toolbox.
After this tutorial you're able to:
- Define input layers and variables for your graphical model
- Add processing tools to your graphical model
- Save results of your graphical model
- Save your graphical model to the Processsing Toolbox
- Create a graphical model for stream delineation
- Create a graphical model for catchment delineation
2. Data preparation
We'll make two graphical models:
- Stream delineation
- Catchment delineation
3. Create the graphical model for stream delineation
Now we're going to create the graphical model for Stream Delineation
1. In the main menu choose Processing | Graphical modeler.
2. Maximize the Model designer window.
3. Under Model Properties add the Name Stream delineation and the Group Hydrology.
This controls how the model will show up in the Processing Toolbox. In this case you'll find the Stream delineation model under the group Hydrology.
4. Before we continue adding the different processing steps, we'll save the model by clicking . The model will be saved in your profile. Choose streamdelineation.model3 as name.
Now we're ready to add different processes for stream delineation to our empty model.
3.1. Mosaic SRTM tiles
The first step is to mosaic the SRTM tiles.
We would like to offer the user the choise to select several tiles at once as input.
1. In the Inputs panel double click on .
2. In the Multiple Input Parameter Definition write DEM Tiles as Description and choose Raster as Allowed layer type. Keep Mandatory checked and click OK.
In this way the user has to select a set of raster layers before the model can run.
3. Switch to the Algorithms panel by clicking on the tab.
4. Search for Build virtual raster and double click on the tool.
5. In the Build virtual raster dialogue replace the text at Description with Mosaic DEM Tiles.
6. Click at Input layers and select DEM Tiles. Click to go back.
7. Change Place each input file into a separate band to No, because we don't want to stack the layers. Check if the dialogue looks like the figure below.
8. Click OK.
Note that we only provide the output names in these tools if the output is a final result. In our case the mosaic is a temporary result.
Now the screen should look like this:
Let's add the next process.3.2. Reproject and clip DEM
The next step to implement in our graphical model is to reproject the DEM mosaic to UTM Zone 32N/WGS-84 and to clip the DEM to the bounding box. This can be done with one tool.
We first need to add the bounding box polygon as an input vector layer.
1. Switch back to the Input panel and double click on Vector Layer.
2. Type Bounding box at Description and choose Polygon as Geometry Type. Keep the Mandatory box checked.
In this way the user needs to provide a bounding box polygon vector layer.
3. Click OK.
4. Now switch to the Algorithms tab and search for the Warp (reproject) algorithm and double click.
5. In the Warp (reproject) dialogue replace the Description with Reproject and clip DEM.
6. At Input layer click the button and choose Algorithm Output.
Because we have only one other algorithm this will be automatically the output from the Mosaic DEM Tiles process.
The Source CRS is known, so keep it blank. We need to change the Target CRS to the one from the provided bounding box layer.
7. At Target CRS click the button and choose Model Input.
It will automatically select the Bounding box layer.
8. Keep the Resampling method to use at Nearest Neighbour so the original pixel values are preserved as much as possible. Set the Nodata value for output bands to -9999. Set the Output file resolution to 30 meters.
The dialogue should now look like this:
We still need to clip to the extent of the bounding box.
9. Click the Show advanced parameters button.
10. Choose here for the Georeferenced extents of the output file to be created the Model input Bounding box layer.
11. Click OK.
Now your screen should look like the figure below.
We can proceed by adding the next step.
3.3. Interpolate voids
Sometimes the DEM has pixels with nodata. These voids need to be interpolated.
1. In the Algorithms panel double click on the Fill nodata tool.
2. Change the Description to Interpolate voids in DEM. Choose as Input layer the output from the Reproject and clip DEM algorithm. Increase the Maximum distance to 100 pixels.
3. Click OK.
Your model should now look like the figure below.
We can proceed with the next step.
3.4. Fill sinks
The next process to add is to fill the sinks in the DEM to get rid of depressions that trap the water flow.
1. In the Algorithms panel look for the SAGA Fill sinks (Wang & Liu) algorithm and double click.
2. In the Fill sinks (wang & liu) dialogue choose for DEM the algorithm output from the previous step. Because we need the filled DEM to be saved to disk we type Filled DEM for Filled DEM.
3. Click OK.
The model now looks like the figure below. Note that the output layer (Filled DEM) is in a green box. You can move the box below the last algorithm.
We can now proceed with implementing the next step.
3.5. Delineate streams
Now we're going to delineate the streams. For that we need as an input the filled DEM from the previous step and a Strahler order threshold that you can calibrate. We'll add that as an integer input to the model.
1. Go back to the Input panel by clicking the Input tab.
2. Double click on Number.
3. In the Number Parameter Definition type Strahler order threshold as Description. The Number type is Integer.
Strahler orders always have a minimum of 1. The maximimum depends on
the area, but we can limit it to 20. We can define a default value of 8.
Keep the Mandatory box checked.
4. Click OK.
5. Go back to the Algorithms tab and double click the SAGA Channel network and drainage basins algorithm.
6. In the Channel network and drainage basins dialogue change the Description to Delineate streams. Choose for Elevation the Filled DEM algorithm output. Choose for Threshold the Strahler order threshold input value. Save Channels to Streams.
7. Click OK.
You can rearrange the boxes a bit. Your model should now be similar to the one in the figure below.
3.6. Snap outlet to delineated stream
The next step is to snap an outlet digitized from a map to the delineated stream from the previous step.
1. Go to the Input panel and double click on Vector Layer.
2. In the Vector Layer Parameter Definition type Outlet on map for the Description and set the Geometry type to Point. Keep the Mandatory box checked.
3. Click OK.
We're going to add another input for the tolerance of the snapping.
4. Double click on Number in the Input panel.
5. In the Number Parameter Definition dialogue type Tolerance as Description, choose Float as Number type, type a minimum value of 30, maximum value of 500 and default value of 100 meters. Keep the Mandatory box checked.
6. Click OK.
7. Go to the Algorithms panel double click the Snap geometries to layer algorithm.
8. In the Snap geometries to layer dialogue change the Description to Snap outlet to delineated stream, choose for Input layer the Outlet on map, for the Reference layer the Channels output from the previous step and for Tolerance the Tolerance input. Change Behavior to Prefer closest point, insert extra vertices where required.
9. Click OK.
Now we need to add the coordinates to the attribute table so we can use them later for the catchment delineation.
10. In the Algorithms panel double click on the Add geometry attributes algorithm.
11. In the Add geometry attributes dialogue type Save outlet with coordinates ad Description. Choose the Snapped geometry output as Input layer and save the layer as Snapped outlet.
12. Click OK.
The model looks now similar to the figure below.
13. Save the model by clicking .
14. Close the Graphical Modeler window.
3.7. Run the Stream delineation model
Now you can find your new model in the Processing Toolbox.
Before running the model, we first need to digitize an outlet.
1. Install the QuickMapServices plugin and add OSM Standard to the map canvas.
2. Find the outlet of the Rur (Roer in Dutch) on the map, where it enters the Meuse (Maas) river.
3. Click the to create a new temporary scratch layer.
4. In the dialogue call the layer Outlet with a Point Geometry type. Set the projection to EPSG: 32632.
5. No need to define attributes. Click OK.
6. The layer is automatically set to editing mode. Click to add a point feature at the outlet.
7. Toggle off editing by clicking and click Save.
Now we can use our Stream delineation model from the Processing Toolbox.
8. In the Processing Toolbox double click Models | Hydrology | Stream delineation.
9. In the Stream Delineation dialogue choose the boundingbox layer as Bounding box, choose the 4 SRTM tiles as DEM Tiles, choose Outlet as Outlet on map, keep the default Strahler order threshold and set the snapping Tolerance to 500 m. Save the Snapped outlet to snapped_outlet.shp, save the Streams to streams.shp and save the Filled DEM to filled_DEM.tif.
10. Click Run. Close the dialogue after processing.
Now we can proceeed with delineating the Rur catchment using a second graphical model.
4. Create the graphical model for catchment delineation
Now we have the snapped outlet and the filled DEM, we can use those layers as an input for a second graphical model to delineate the Rur catchment.
1. In the main menu go to Processing | Graphical modeler...
2. Under Model properties type Catchment delineation as Name and Hydrology as Group.
3. Save the model as catchmentdelineation.model3.
4.1. Define the inputs
We need to define the model inputs first.
1. In the Input panel double click on Raster layer.
2. In the Raster Layer Parameter Definition dialogue type Filled DEM as Description and keep the Mandatory box checked.
3. Click OK.
4. Double click on Number in the Input panel.
5. In the Number Parameter Definition dialogue type X Coordinate Outlet as Description, keep Float as Number type and leave everything else as default.
6. Click OK.
7. Do the same for the Y Coordinate.
Now the inputs are defined we can use them in the algorithms.4.2. Delineate the catchment raster
Now we can add the algorithms to derive the catchment.
1. Add the SAGA Upslope area algorithm from the Algorithms panel.
2. In the Upslope area dialogue change the Description to Delineate catchment. Link the Target X coordinate to X Coordinate Outlet and the Target Y coordinate to Y Coordinate Outlet. Use the Filled DEM input as Filled DEM. For Method use D8 and leave other settings as default.
3. Click OK.
In the next step we're going to polygonize this catchment raster layer.
4.3. Polygonize the catchment boundary
Now we need to polygonize the raster layer with the catchment.
1. In the Algorithms panel choose Polygonize (raster to vector).
2. In the dialogue change the Description to Polygonize catchment. Choose the Upslope area as Input layer and leave the rest as default.
3. Click OK.
Now we need to select and save the attribute with value 100, which is the catchment.
4. In the Algorithms panel choose the Extract by attribute algorithm.
5. In the Extract by attribute dialogue replace the Description with Save catchment polygon only. As Input layer choose the output of the previous algorithm. Type for Selection attribute DN (that's the field where with the values 0 and 100), keep the Operator as = and type 100 for the Value, so we'll select the feature with DN = 100, which is the catchment boundary. Save the Extracted polygon as Catchment Boundary.
6. Click OK.
The model should now look like the figure below.
7. Save the model by clicking the button and close the Graphical Modeler window.
Next, we'll run the model.
4.4. Run the Catchment delineation model
Now we're ready to run the Catchment delineation model.
1. Open the attribute table of the Snapped outlet layer so we can copy the coordinates later.
2. In the Processing Toolbox choose Models | Hydrology | Catchment delineation.
3. In the Catchment Delineation dialogue choose the filled_DEM layer as Filled DEM. Copy the X and Y coordinate of the outlet from the snapped_outlet layer attribute table. Save the Catchment Boundary as Rur_catchment.shp.
4. Click Run. Close the dialogue after processing.
The result should look similar to the figure below.