10.2 Raster Reclassification
Turning continuous rasters into classes, and remapping class values for analysis.
Key takeaways
- Reclassification replaces cell values with new values according to rules you define.
- Common patterns: binary mask, equal-width bins, thresholds, code lookup.
- It's the cheapest way to turn a messy raster into a clean analytic layer.
Introduction
Before you can analyse most rasters, you need to simplify them — reduce millions of unique values to a handful of classes. Reclassification is the operation that does so, and it's one of the most-used tools in raster GIS. This short lesson covers the main patterns.
The concept
Given an input raster with values v, reclassification assigns each cell a new value v' according to a rule:
- Binary mask —
v' = 1 if v in [10, 20] else 0. - Bin — slice into ordered classes.
- Threshold — above / below a cut-off.
- Lookup — replace each value with a mapped value.
Numpy patterns
1import numpy as np
2import rasterio
3[object Object]
4[object Object]
5[object Object]
6[object Object]
7[object Object]
8[object Object]
9Save the result:
1profile.update(dtype='uint8', nodata=0)
2with rasterio.open('classes.tif', 'w', **profile) as dst:
3 dst.write(classes, 1)In QGIS
- Raster → Raster Calculator for simple expressions.
- Processing → Reclassify by Table for a value-lookup.
- Raster → Conversion → Polygonize to turn classes into vector polygons after reclassifying.
In gdal_calc.py
gdal_calc.py -A dem.tif --outfile=lowland.tif --calc="A<100" --NoDataValue=0Quick and scriptable.
Classification methods for continuous → discrete
When binning continuous data:
- Equal interval — same data range per class. Even across the value range, bad for skewed distributions.
- Quantile — same cell count per class. Evens the map but merges different values.
- Natural breaks (Jenks) — minimise within-class variance. Default for cartography.
- Standard deviation — classes around the mean.
- Manual — breaks chosen for domain meaning (100 m contours, PM2.5 WHO thresholds).
Module 16.2 covers this in detail for cartography; the same logic applies to raster analysis.
Use cases
- Binary masks — inputs to site suitability, flooded-area maps.
- Risk tiers — slope < 10 = low, 10–20 = medium, > 20 = high.
- Class recoding — standardising different providers' land-cover codes.
- Quality flags — cloud mask from Sentinel QA band.
Avoid lossy reclassification
Every reclassification loses information. Think twice before overwriting originals:
- Keep the original raster.
- Save reclass outputs under distinct names.
- Record the rules (in a sidecar JSON or metadata).
Building a lookup table programmatically
import pandas as pdVectorised lookup is clean and fast for small lookup tables.
Nodata handling
Always consider what happens to nodata cells:
- Binary mask: set them to 0, or keep them nodata.
- Classification: a dedicated "nodata" class often clearer than propagating nodata.
- Document in your output metadata.
Self-check exercises
1. Equal interval vs natural breaks — which for a right-skewed variable like population density?
Natural breaks (Jenks). Equal interval would give you one class covering almost all cells and several empty high-density classes. Jenks adapts to the distribution, finding break points that minimise within-class variance — producing more balanced classes that reveal the spatial pattern.
2. You reclassify slope into low/medium/high risk. Why keep the original slope raster?
Because future analyses may need different thresholds, and reclassification is lossy — once binned, you can't recover the original values. Keeping the original lets you re-bin as understanding improves. Store the reclass rules (e.g., as JSON) so results are reproducible.
3. Your lookup table maps 10 old codes to new codes, but some cells in the output remain zero. Why?
Those cells had codes not in your lookup — possibly rare classes or data errors. Explicitly handle them (add to the lookup as "other" or treat as nodata). Always check np.unique(output) against the expected set to catch silent misses.
Summary
- Reclassification remaps raster cell values by rule.
- Patterns: binary mask, tiered bins, threshold, code lookup.
- Classification methods (Jenks, quantile, equal interval) influence outcomes.
- Keep originals; document rules; handle nodata explicitly.
Further reading
- Tomlin, C. D. — Geographic Information Systems and Cartographic Modeling, reclassification chapter.
gdal_calc.pydocumentation.- QGIS Processing Toolbox —
Reclassify by Table. - Brewer & Pickle — Evaluation of Methods for Classifying Epidemiological Data on Choropleth Maps.