Setting extents with masks
The extent of a layer can be set using a second layer, which acts as a mask. This recipe shows you how to do this.
How to do it…
To mask the DEM with the watershed mask, follow these steps:
Open the
watershed.tif
layer and thedem.tif
layer.Open the Raster Calculator algorithm present in the Processing Toolbox menu.
In Main input layer, select the DEM, and in the Additional layers field, select the watershed layer.
In the Formula field, enter the formula, a*b.
Click on Run to run the algorithm. You will get a masked DEM, as follows:
How it works…
When using the raster calculator, all operations involving a no-data value will result in another no-data value. This means that, when multiplying the DEM layer and the mask layer, in the cells that contain no-data values in the mask layer, the value in the resulting layer will be a no-data value, no matter which elevation value is found in the DEM layer for this cell.
As cells inside the watershed in the mask layer have a value...