Raster GIS

Using the raster calculator (NDVI example)

Compute new rasters from band values with the raster calculator, using band references, NoData-safe arithmetic and conditions, with NDVI as the worked example.

Intermediate2 min read

You will learn

  • Reference rasters and bands in expressions.
  • Compute an index and choose the output type.
  • Use conditions and NoData handling.

Prerequisites

Data for this tutorial

Multispectral 2024 (synthetic) Download multispectral_2024.tif

Format
GeoTIFF, 5 bands, UInt16 (reflectance × 10000)
Geometry
Raster, 280 × 240 cells of 60 m
CRS
EPSG:32643 (WGS 84 / UTM zone 43N)
Content
Bands 1 Blue, 2 Green, 3 Red, 4 NIR, 5 SWIR1; 0 = NoData
In Orbis
Browser panel ▸ Tutorial sample data (synthetic) ▸ Multispectral 2024, or Load complete tutorial pack.

DEM 30 m (synthetic) Download dem.tif

Format
GeoTIFF, 1 band, Float32
Geometry
Raster, 560 × 480 cells of 30 m
CRS
EPSG:32643 (WGS 84 / UTM zone 43N)
Content
Elevations 450.01 to 678.95 m; NoData -9999 in the south-west corner
In Orbis
Browser panel ▸ Tutorial sample data (synthetic) ▸ DEM 30 m, or Load complete tutorial pack.

Licence: CC0 1.0. All tutorial data is synthetic and generated by Orbis. About the datasets

The task

The normalised difference vegetation index, NDVI = (NIR − Red) / (NIR + Red), is high for vegetation and low for water and built-up land. You will compute it from the five-band image, whose band 4 is near infrared and band 3 is red.

Steps

  1. Add Multispectral 2024 from the tutorial data.
  1. Open Raster ▸ Raster calculator… (Ctrl+Alt+R). Under Input rasters, tick Multispectral 2024 (synthetic); it gets the name A.
  1. Type the expression, or click the band buttons (A@1 … A@5) and operators below the box:

    (A@4 - A@3) / (A@4 + A@3)

    A@4 is band 4 of raster A. Keep Output data type at Float32 (NDVI has decimals).

    The raster calculator with the multispectral image as A and the NDVI expression
    The NDVI expression in the raster calculator.
  1. Click Run. A layer Calculator result is added. Style it with Single-band pseudocolour and a green ramp.
  1. Conditions produce 1 for true and 0 for false. With the DEM as A, A@1 > 600 marks cells above 600 m; if(A@1 > 600, A@1, nodata()) keeps the elevation only there.

Expected result

An NDVI raster from about -0.43 (water) to 0.87 (dense vegetation), with a mean of about 0.61, on the same 60 m grid as the image.

Common mistakes

  • Integer output. Output data type Int16 or Byte would round NDVI to -1, 0 or 1. Use Float32.
  • Wrong band numbers. Band order depends on the sensor. The tutorial image has 1 Blue, 2 Green, 3 Red, 4 NIR, 5 SWIR1.

Troubleshooting

  • "cannot be combined pixel by pixel". The input rasters have different grids. Choose a resampling method under If input grids differ.
  • Unknown raster. The letter in the expression must match a ticked input; aliases can be changed next to each raster.