Raster calculator — Tool (QGIS)

In QGIS: Raster › Raster Calculator…; in the Processing Toolbox › Raster analysis › Raster calculator.

Realises:

Settings that matter

  • Raster bands: each band is written "layer name@band", e.g. "B08@1". Double-click a band to put it in the expression.
  • Expression: arithmetic (+ − * /, ^, sqrt, ln), comparisons (=, <, >=; they give 1 for true and 0 for false), AND, OR, and if(condition, value if true, value if false). NDVI: ("B08@1" - "B04@1") / ("B08@1" + "B04@1").
  • Output layer: a GeoTIFF file; Output format GeoTIFF.
  • Spatial extent, Resolution and Output CRS: the grid of the result. Use selected layer extent takes them from one input. Inputs on another grid are resampled to it.

Watch out

  • Masking to NoData. There is no NoData setting. Dividing by zero gives NoData, so dividing by a condition removes the cells where it is false: (...) / ("SCL@1" = 4 OR "SCL@1" = 5 OR "SCL@1" = 6). An if(…, …, -9999) instead writes −9999 as a value, which statistics then include, unless you set it as NoData afterwards (Raster › Conversion › Translate, Assign a specified NoData value).
  • Integers are safe here. The calculator computes in floating point and writes 32-bit floats, so integer bands such as Sentinel-2’s 16-bit values give correct ratios. The GDAL Raster calculator (Raster miscellaneous) does not: with 16-bit unsigned inputs a negative difference wraps around, and negative NDVI (water) comes out as large positive values.
  • Any input cell with NoData gives NoData in the result.
  • Check the result’s range (Layer Properties › Information, or the histogram). An index outside its possible range, such as NDVI above 1, means a wrong input (see scale and offset).

Checked in QGIS 4.2.2, November 2026. Names and options can differ in other versions.