Unit 05 - Raster processing¶
Raster data processing is always limited to the current computational region.
Let’s demostrate raster processing on map algebra based computation of NDVI (Normalized difference vegetation index). The key GRASS module that allows a user to do the map algebra is r.mapcalc. A GUI tool for map algebra can be launched from or by Raster map calculator from the main toolbar.
To compute NDVI, the red (VIS) and near-infrared (NIR) bands are
required. In the case of Sentinel-2, it refers to 4th and 8th
band. Missing Sentinel-2 8th band can be imported as explained in
Unit 03 - Data Management from L2A_T32UPB_20170706T102021_B08_10m.jp2
file.
Corresponding command (map names shorten):
r.mapcalc expression="ndvi = float(B08_10m - B04_10m) / ( B08_10m + B04_10m )"
Note
Because all input raster maps are CELL type (integer) at
least one sub-result must be converted to floating-point by
float()
function. Otherwise result would be also CELL
map (integer: -1, 0, 1).
Result requires some improvements:
- default color table viridis is not suitable for NDVI values
- NDVI was computed also in cloudy areas
The first shortcoming can be easily solved by changing color table to
ndvi as described in Color table section. The second requires
setting a mask to ignore cloudy areas by the computation. Raster mask
can be created by r.mask. Like other modules from the
r.*
family, it operates in the current computational region.
Let’s create raster mask from cloud mask vector map in inverse manner.
r.mask -i vector=MaskFeature
Note
Cloud mask provided by Sentinel products is not perfect, but it is a good starting point for us.
A mask can be deactivated r.mask -r
command.