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.
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
- Add Multispectral 2024 from the tutorial data.
- Open Raster ▸ Raster calculator… (Ctrl+Alt+R). Under Input rasters, tick Multispectral 2024 (synthetic); it gets the name A.
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@4is band 4 of raster A. Keep Output data type at Float32 (NDVI has decimals).
The NDVI expression in the raster calculator.
- Click Run. A layer Calculator result is added. Style it with Single-band pseudocolour and a green ramp.
- Conditions produce 1 for true and 0 for false. With the DEM as A,
A@1 > 600marks 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.