Expressions on Raster Data

In many applications where raster data is used, it is necessary to do calculations on single-pixel values. For example, one often wants to convert or normalize data. Furthermore, if there are several data sets or raster bands, it is interesting to combine them and to correlate them with each other. Raster calculators are often used for this purpose. In Geo Engine, this calculator is called Expression. Below we show a short example with our new raster expression syntax.

The idea

We use two infrared and near-infrared bands from Sentinel 2 [1] to generate an NDVI product for central Hesse, Germany. The NDVI index is then converted into four different classes: very low, low, medium and high.

The steps

First, we add the two raster bands as datasets. To do this, we can access the Sentinel-2 data via the Data Repository. The Geo Engine can display datasets stacked on top of each other or side by side as a grid.

Then, we look for the expression operator. For this we go to the operator list and select the corresponding raster operator.

In the input dialog, we can enter an expression. We can access the raster pixels with the letters A and B, respectively. Besides simple calculations, we can use variables and branches here.

let ndvi = (A - B) / (A + B);
if ndvi < 0 {
    1
} else if ndvi < 0.25 {
    2
} else if ndvi < 0.75 {
    3
} else {
    4
}

As a no-data value, we use a value outside the classification and as an output data type, a byte is enough for the four values in our case. When we apply the operator, a new layer appears on the map. We can color it according to the four classes and get the classified overview accordingly.

Conclusion

Raster expressions can be used to combine multiple rasters on a pixel-by-pixel basis. This ranges from simple to complex mathematical expressions and can be efficiently calculated with the Geo Engine. The outputs can be continuous as well as classified data. These could in turn be used in new use cases. An example would be fertilizer maps for farmers based on the classification created here.

Data citation

  1. M. Drusch, U. Del Bello, S. Carlier, O. Colin, V. Fernandez, F. Gascon, B. Hoersch, C. Isola, P. Laberinti, P. Martimort, A. Meygret, F. Spoto, O. Sy, F. Marchese, P. Bargellini: Sentinel-2: ESA’s Optical High-Resolution Mission for GMES Operational Services, Remote Sensing of Environment, Volume 120, 2012, Pages 25-36, ISSN 0034-4257, https://doi.org/10.1016/j.rse.2011.11.026.