Apply Classified Height Bands to a CHM and Export a Map in QGIS

QGIStutorialCHMvisualisationdrone mappingaerial surveyterrainPython
Apply Classified Height Bands to a CHM and Export a Map in QGIS

A raw Canopy Height Model (CHM) raster loaded into QGIS shows a grey gradient by default. To make it readable for clients or reports, you need a classified colour scheme with a legend. This script applies one automatically and exports a print-ready JPEG.

Before — the raw CHM, grey gradient, hard to read absolute heights from:

Raw grayscale Canopy Height Model — bright patches are tall canopy, dark patches are ground, but exact heights aren't readable at a glance

What it does

The style_chm.py script applies a classified height-band colour scheme to a CHM raster. Pixels are grouped into five fixed height ranges, each assigned a distinct colour:

Height rangeColourInterpretation
0–1 mTanBare ground
1–3 mLight greenLow vegetation / understorey
3–8 mYellowSmall trees
8–15 mForest greenMedium trees
15 m+Dark redTall canopy

The script also exports a static JPEG map with a legend, north arrow, and scale bar built in — useful for reports or quick sharing without needing Layout Designer. Here’s the real output on a forest estate survey:

Classified Canopy Height Model with a five-band legend — tan for bare ground through dark red for tall canopy — plus north arrow and distance axes

Output:

  • {chm_name}_classified.jpg — static map image
  • {chm_name}_classified.tif — georeferenced classified raster added to QGIS project

What you need

  • QGIS 3.28 or newer
  • numpy, rasterio, matplotlib (matplotlib may need install via OSGeo4W)
  • A CHM raster with “chm” in the layer name, checked in the Layers panel
  • The style_chm.py script from the Terrain Analysis Pack

Steps

  1. Run generate_chm.py to create the CHM raster first (see the CHM tutorial). Or load an existing CHM.
  2. Check (tick) the CHM raster in the Layers panel. The layer name must contain “chm”.
  3. Open Plugins → Python Console → Show Editor.
  4. Paste the script and click Run.

The classified JPEG and GeoTIFF are saved in the CHM directory. The GeoTIFF is loaded into the QGIS project.

Customising the height bins

The height ranges and colours are defined in the HEIGHT_BINS list inside the script. You can edit them to match the typical canopy heights in your study area — for example, in a low-growing crop plantation the bands might stop at 10 m, while in a mixed forest they might extend to 40 m+.

Get the script

style_chm.py is part of the Terrain Analysis Pack — five terrain analysis scripts for QGIS at $35 USD.