Outdated version of the documentation. Find the latest one here.

17.10. Calculatorul raster. Valorile fără-date

Note

În această lecție vom vedea cum se utilizează calculatorul raster pentru a efectua unele operații asupra straturilor raster. Vom explica, de asemenea, ce sunt valorile fără-date și modul în care lucrează cu ele calculatorul și alți algoritmi

Calculatorul raster reprezintă unul dintre cei mai puternici algoritmi. Este un algoritm foarte flexibil și versatil, care poate fi folosit în diverse calcule, și care va deveni în curând o parte importantă a setului dvs. cu instrumente.

În această lecție vom efectua unele calcule, majoritatea simple, cu ajutorul calculatorului raster. Acest lucru ne va permite să observăm modul de gestionare a unor situații particulare cu care ne-am putea confrunta. Înțelegerea acestor aspecte este importantă pentru obținerea ulterioară a rezultatelor așteptate și, de asemenea, pentru deprinderea tehnicilor comune care se pot aplica.

Deschideti proiectul QGIS corespunzător acestei lecții și veți vedea că ea conține mai multe straturi raster.

Acum deschideți caseta de instrumente și caseta de dialog corespunzătoare calculatorului raster.

../../../_images/calculator_dialog.png

Note

Interfața diferă pentru versiunile recente.

Dialogul conține 2 parametri.

  • The layers to use for the analysis. This is a multiple input, that meaning that you can select as many layers as you want. Click on the button on the right–hand side and then select the layers that you want to use in the dialog that will appear.
  • The formula to apply. The formula uses the layers selected in the above parameter, which are named using alphabet letters (a, b, c...) or g1, g2, g3... as variable names. That is, the formula a + 2 * b is the same as g1 + 2 * g2 and will compute the sum of the value in the first layer plus two times the value in the second layer. The ordering of the layers is the same ordering that you see in the selection dialog.

Warning

Calculator ține cont de majuscule/minuscule.

Pentru a începe, vom schimba unitățile DEM-ului din metri în picioare. Formula de care avem nevoie este:

h' = h * 3.28084

Selectați DEM-ul din câmpul straturilor și introduceți a * 3.28084 în câmpul formulei.

Warning

Pentru utilizatorii care nu sunt englezi: folosiți întotdeauna ”.”, nu ”,”.

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.

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.

Open the algorithm dialog again, select the accflow layer as the only input layer, and enter the following formula: log(a).

Acesta este stratul pe care îl veți obține.

../../../_images/log.png

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.

../../../_images/identify.png

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:

a/a * b

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)

Acesta este stratul rezultat.

../../../_images/masked.png

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.

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.

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.

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.

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.

În acest caz, nu dispunem de un strat pentru a-l utiliza drept mască, dar îl putem crea cu ajutorul calculatorului.

Pornește calculatorul folosind DEM-ul doar ca pe un strat de intrare, și următoarea formulă

ifelse(abs(a-1250) < 250, 1, 0/0)

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.

Rezultatul are o valoare de 1 în interiorul gamei în care dorim să lucrăm, și valori fără-date în celulele din exterior.

../../../_images/elevation_mask.png

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.

Now you just have to multiply it by the slope layer included in the project, and you will get the desired result.

All that can be done in a single operation with the calculator. We leave that as an exercise for the reader.