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

QGIStutorialCHMvisualisationdrone mappingPython

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.

What it does

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

Height rangeColourInterpretation
0–1 mDark green/blackBare ground
1–3 mOliveLow vegetation / understorey
3–8 mYellow-greenSmall trees
8–15 mGreenMedium canopy
15–20 mTealTall trees
20–25 mBlueVery tall trees
25–30 mPurpleExceptional height
30 m+RedOutliers / structures

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.

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.