In this recipe, we will show you how to perform terrain analysis in QGIS. Terrain analysis algorithms assume certain characteristics in the DEMs that are used as inputs, so it is important to know them and prepare these DEMs if they are needed. This recipe shows you how to do this.
Open the dem_to_prepare.tif layer. This layer contains a DEM in the EPSG:4326 CRS and elevation data in feet. These characteristics are unsuitable to run most terrain analysis algorithms, so we will modify this layer to get a suitable one.
a * 0.3048 in the Formula field. Run the algorithm.Most of the algorithms that we are going to use assume that the horizontal units (the unit used to measure the size of the cell) are the same as the units used in the elevation values that are contained in the layer. If the layer does not meet this requirement, the result of the analysis will be wrong.
Our input layer uses a CRS with geographic coordinates (degrees). As elevation cannot be measured in degrees, the layer cannot have the same units for horizontal and vertical distances, and it is not ready to be used for terrain analysis.
By reprojecting the layer to the EPSG:3857 CRS, we get a new layer in which coordinates are expressed in meters. This is a unit that is more suitable for the type of analysis that we plan to run. Actually, after the reprojection, the units are meters only near the equator, but this gives us enough precision for this case. If more precise calculations are needed, a local projection system should be used.
The next step is converting the elevation values in feet to elevation values in meters. Knowing that 1 foot = 0.3048 meter, we just have to use the calculator to apply this formula and convert the values in the reprojected layer.
There are other things that must be taken into account when running a terrain analysis algorithm to ensure that results are correct.
One common problem is dealing with different cell sizes. An assumption that is made by most terrain analysis algorithms (and also most of the ones not related to terrain analysis) is that cells are square. That is, their horizontal and vertical values are the same. This is the case in our input layer (you can verify this by checking the layer properties), but it may not be true for other layers.
In this case, you should export the layer and define the sizes of the cells of the exported layer to have the same value. Right-click on the layer name and select Save as.... In the save dialog that will appear, enter the new sizes of the cells in the lower part of the dialog:
