11.4 Contour Lines from DEMs
Extracting isolines of elevation from a raster — for visualisation, hydrology, and cartography.
Key takeaways
- Contours are lines of constant elevation, derived by interpolating a DEM.
- Interval choice is a cartographic decision, not just a technical one.
- Contours are the most time-honoured way to visualise terrain on paper.
Introduction
Long before hillshade existed, topographic maps used contour lines — isolines of equal elevation — to communicate terrain. They remain the most precise visual description of elevation for many uses, from hiking maps to engineering drawings. This short lesson covers contour generation and cartographic choices.
The algorithm
Given a DEM, contouring traces every cell edge where elevation crosses a contour value:
- For contour 500 m, every pair of adjacent cells where one is < 500 and the other is ≥ 500 defines an edge.
- Connect those edges into lines.
- Output as vector polylines.
GDAL implements this as gdal_contour:
gdal_contour -a elev -i 10 dem.tif contours.gpkg-a elev— name of the elevation attribute.-i 10— contour interval, 10 units (metres here).- Or
-fl 100 500 1000— specific levels.
Smoothing
Raw contours follow the cell grid and look stair-stepped. Smooth them with:
- A minor Gaussian smooth of the DEM before contouring.
- Post-smooth the contour lines (Chaikin's algorithm, B-splines).
Over-smoothing loses detail; under-smoothing looks crude. Cartographers tune it by eye.
Choosing an interval
Key cartographic choice. Common guidelines:
- Large-scale topographic maps — 5 or 10 m intervals.
- Hiking maps — 10 or 20 m.
- Regional overview — 50 or 100 m.
- Continental — 500 m or 1 000 m.
The interval should reveal the terrain's character without cluttering. In steep country, use larger intervals; in flat country, smaller.
Many maps use a combination: index contours every 5th or 10th line are thicker with elevation labels; intermediate contours are thinner and unlabelled.
Labelling
Contour labels are placed:
- Along index contours.
- Oriented uphill (reader's up = contour's higher side).
- Spaced so labels are always nearby.
Automatic label placement engines in QGIS (PAL) or ArcGIS handle most cases; tweak by hand for publication-quality maps.
Supplementary contours
In very flat terrain, add half-interval dashed "supplementary" contours to reveal detail without cluttering steeper areas.
Depression contours
Closed contours that enclose a lower area are usually drawn with short hachure marks on the downhill side to distinguish them from peaks. Some data sources mark these explicitly; others rely on the reader to infer.
Modern uses
Beyond topographic maps, contours are used for:
- Engineering site plans — drainage, grading.
- Archaeological surveys — subtle earthworks at sub-metre intervals.
- Meteorology — isobars, isotherms (same concept on pressure/temperature surfaces).
- Bathymetric charts — ocean depth contours.
Tools
gdal_contour— command-line.- QGIS Raster → Extraction → Contour.
matplotlib.contour— Python plotting.richdem.TerrainAttribute— various terrain products.contourGDAL C API — for application embedding.
Self-check exercises
1. What's the difference between index and intermediate contours?
Index contours are every 5th or 10th contour — thicker, labelled with elevation. Intermediate contours are the thinner lines between them, usually unlabelled. The visual hierarchy lets readers quickly determine elevation values from the nearest index contour.
2. Your contours from a 1 m LiDAR DEM look noisy and squiggly. What helps?
(1) Smooth the DEM slightly before contouring (Gaussian with sigma = 1–2 cells). (2) Post-smooth contours with a polyline simplification (Douglas-Peucker with small tolerance, or Chaikin for visual smoothness). (3) Increase the contour interval — 1 m from 1 m LiDAR captures real but noise-like variation that often isn't helpful at map scale.
3. Why distinguish a peak from a pit when both are closed contours?
Plain contours are ambiguous — a closed contour enclosing a higher area looks identical to one enclosing a lower area. Cartographers use hachures (short tick marks) on the downhill side of depression contours to mark pits. Symbology conventions vary; always check the map legend.
Summary
- Contours are isolines of elevation extracted from a DEM.
- Interval choice balances clarity and detail.
- Index / intermediate / supplementary hierarchy organises dense sets.
- Contour maps remain valuable for engineering, archaeology, and cartography.
Further reading
- Imhof, E. — Cartographic Relief Presentation.
- USGS — Topographic Maps: Symbols legend poster.
gdal_contourdocumentation.- Patterson, T. — essays on terrain cartography at shadedrelief.com.