You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/training_manual/processing/no_data.rst
+51-16Lines changed: 51 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,65 +28,100 @@ To start with, we will change the units of the DEM from meters to feet. The form
28
28
29
29
::
30
30
31
-
h' = h * 3.28084
31
+
h' = h * 3.28084
32
32
33
33
Select the DEM in the layers field and type ``a * 3.28084`` in the formula field.
34
34
35
35
.. warning:: For non English users: use always ".", not ",".
36
36
37
-
Click *Run* to run the algorithm. You will get a layer that has the same appearance of the input layer, but with different values. The input layer that we used has valid values in all its cells, so the last parameter has no effect at all.
37
+
Click *Run* to run the algorithm. You will get a layer that has the same appearance of the input layer, but with different values.
38
+
The input layer that we used has valid values in all its cells, so the last parameter has no effect at all.
38
39
39
-
Let's now perform another calculation, this time on the *accflow* layer. This layer contains values of accumulated flow, a hydrological parameter. It contains those values only within the area of a given watershed, with no--data values outside of it. As you can see, the rendering is not very informative, due to the way values are distributed. Using the logarithm of that flow accumulation will yield a much more informative representation. We can calculate that using the raster calculator.
40
+
Let's now perform another calculation, this time on the *accflow* layer.
41
+
This layer contains values of accumulated flow, a hydrological parameter.
42
+
It contains those values only within the area of a given watershed, with no--data values outside of it.
43
+
As you can see, the rendering is not very informative, due to the way values are distributed.
44
+
Using the logarithm of that flow accumulation will yield a much more informative representation.
45
+
We can calculate that using the raster calculator.
40
46
41
-
Open the algorithm dialog again, select the *accflow* layer as the only input layer, and enter the following formula: ``log(a)``.
47
+
Open the algorithm dialog again, select the *accflow* layer as the only input layer,
48
+
and enter the following formula: ``log(a)``.
42
49
43
50
Here is the layer that you will get.
44
51
45
52
.. figure:: img/no_data/log.png
46
53
47
-
If you select the *Identify* tool to know the value of a layer at a given point, select the layer that we have just created, and click on a point outside of the basin, you will see that it contains a no--data value.
54
+
If you select the *Identify* tool to know the value of a layer at a given point,
55
+
select the layer that we have just created, and click on a point outside of the basin,
56
+
you will see that it contains a no--data value.
48
57
49
58
.. figure:: img/no_data/identify.png
50
59
51
-
For the next exercise we are going to use two layers instead of one, and we are going to get a DEM with valid elevation values only within the basin defined in the second layer. Open the calculator dialog and select both layers of the project in the input layers field. Enter the following formula in the corresponding field:
60
+
For the next exercise we are going to use two layers instead of one,
61
+
and we are going to get a DEM with valid elevation values only within the basin defined in the second layer.
62
+
Open the calculator dialog and select both layers of the project in the input layers field.
63
+
Enter the following formula in the corresponding field:
52
64
53
65
::
54
66
55
-
a/a * b
67
+
a/a * b
56
68
57
-
``a`` refers to the accumulated flow layer (since it is the first one to appear in the list) and ``b`` refers to the DEM. What we are doing in the first part of the formula here is to divide the accumulated flow layer by itself, which will result in a value of 1 inside the basin, and a no--data value outside. Then we multiply by the DEM, to get the elevation value in those cells inside the basin (``DEM * 1 = DEM``) and the no--data value outside (``DEM * no_data = no_data``)
69
+
``a`` refers to the accumulated flow layer (since it is the first one to appear in the list) and ``b`` refers to the DEM.
70
+
What we are doing in the first part of the formula here is to divide the accumulated flow layer by itself,
71
+
which will result in a value of 1 inside the basin, and a no--data value outside.
72
+
Then we multiply by the DEM, to get the elevation value in those cells inside the basin (``DEM * 1 = DEM``)
73
+
and the no--data value outside (``DEM * no_data = no_data``)
58
74
59
75
Here is the resulting layer.
60
76
61
77
.. figure:: img/no_data/masked.png
62
78
63
79
64
-
This technique is used frequently to *mask* values in a raster layer, and is useful whenever you want to perform calculations for a region other that the arbitrary rectangular region that is used by raster layer. For instance, an elevation histogram of a raster layer doesn't have much meaning. If it is instead computed using only values corresponding to a basin (as in he case above), the result that we obtain is a meaningful one that actually gives information about the configuration of the basin.
80
+
This technique is used frequently to *mask* values in a raster layer,
81
+
and is useful whenever you want to perform calculations for a region
82
+
other that the arbitrary rectangular region that is used by raster layer.
83
+
For instance, an elevation histogram of a raster layer doesn't have much meaning.
84
+
If it is instead computed using only values corresponding to a basin (as in he case above),
85
+
the result that we obtain is a meaningful one that actually gives information about the configuration of the basin.
65
86
66
-
There are other interesting things about this algorithm that we have just run, apart from the no--data values and how they are handled. If you have a look at the extents of the layers that we have multiplied (you can do it double--clicking on their names of the layer in the table of contents and looking at their properties), you will see that they are not the same, since the extent covered by the flow accumulation layer is smaller that the extent of the full DEM.
87
+
There are other interesting things about this algorithm that we have just run,
88
+
apart from the no--data values and how they are handled.
89
+
If you have a look at the extents of the layers that we have multiplied
90
+
(you can do it double-clicking on the names of the layer in the table of contents and looking at their properties),
91
+
you will see that they are not the same, since the extent covered by the flow accumulation layer is smaller that the extent of the full DEM.
67
92
68
-
That means that those layers do not match, and that they cannot be multiplied directly without homogenizing those sizes and extents by resampling one or both layers. However, we did not do anything. QGIS takes care of this situation and automatically resamples input layers when needed. The output extent is the minimum covering extent calculated from the input layers, and the minimum cell size of their cellsizes.
93
+
That means that those layers do not match, and that they cannot be multiplied directly
94
+
without homogenizing those sizes and extents by resampling one or both layers.
95
+
However, we did not do anything. QGIS takes care of this situation and automatically resamples input layers when needed.
96
+
The output extent is the minimum covering extent calculated from the input layers, and the minimum cell size of their cellsizes.
69
97
70
-
In this case (and in most cases), this produces the desired results, but you should always be aware of the additional operations that are taking place, since they might affect the result. In cases when this behaviour might not be the desired, manual resampling should be applied in advance. In later chapters, we will see more about the behaviour of algorithms when using multiple raster layers.
98
+
In this case (and in most cases), this produces the desired results,
99
+
but you should always be aware of the additional operations that are taking place, since they might affect the result.
100
+
In cases when this behaviour might not be the desired, manual resampling should be applied in advance.
101
+
In later chapters, we will see more about the behaviour of algorithms when using multiple raster layers.
71
102
72
103
73
-
Let's finish this lesson with another masking exercise. We are going to calculate the slope in all areas with an elevation between 1000 and 1500 meters.
104
+
Let's finish this lesson with another masking exercise.
105
+
We are going to calculate the slope in all areas with an elevation between 1000 and 1500 meters.
74
106
75
107
In this case, we do not have a layer to use as a mask, but we can create it using the calculator.
76
108
77
109
Run the calculator using the DEM as only input layer and the following formula
78
110
79
111
::
80
112
81
-
ifelse(abs(a-1250) < 250, 1, 0/0)
113
+
ifelse(abs(a-1250) < 250, 1, 0/0)
82
114
83
-
As you can see, we can use the calculator not only to do simple algebraic operations, but also to run more complex calculation involving conditional sentences, like the one above.
115
+
As you can see, we can use the calculator not only to do simple algebraic operations,
116
+
but also to run more complex calculation involving conditional sentences, like the one above.
84
117
85
118
The result has a value of 1 inside the range we want to work with, and no-data in cells outside of it.
86
119
87
120
.. figure:: img/no_data/elevation_mask.png
88
121
89
-
The no-data value comes from the 0/0 expression. Since that is an undetermined value, SAGA will add a NaN (Not a Number) value, which is actually handled as a no-data value. With this little trick you can set a no-data value without needing to know what the no--data value of the cell is.
122
+
The no-data value comes from the 0/0 expression. Since that is an undetermined value,
123
+
SAGA will add a NaN (Not a Number) value, which is actually handled as a no-data value.
124
+
With this little trick you can set a no-data value without needing to know what the no--data value of the cell is.
90
125
91
126
Now you just have to multiply it by the slope layer included in the project, and you will get the desired result.
0 commit comments