Raster to Contours
Generate contour lines from raster elevation data
What Are Contour Lines?
Contour lines β also called isolines, isohypses, isobaths or level curves β are lines that connect points of equal value across a continuous surface. The most familiar contours are topographic: the brown lines on a hiking map that connect points of equal elevation. The same idea applies to bathymetry (isobaths under water), atmospheric pressure (isobars on a weather map), temperature (isotherms), rainfall (isohyets) and any other continuous raster you can imagine.
The Raster to Contours tool on gis.tools generates vector contour lines from a raster GeoTIFF entirely in the browser. People search for "contour lines from dem", "generate contours raster", "contour generator gis", "qgis contour from raster", "geotiff to contours" and "elevation contour lines" because contours are the cartographic foundation of nearly every topographic map ever printed and remain the clearest way to communicate continuous surface information on paper or screen.
The output is a GeoJSON or Shapefile-ready set of LineString features, each tagged with the elevation (or whatever value) it represents. These can be styled, exported, joined to attribute tables, and used as input to further analysis.
How Contour Generation Works
Contour generation is a classic computational geometry problem. The dominant algorithm β used by GDAL's gdal_contour, ArcGIS Spatial Analyst's Contour tool and QGIS β is a variant of the Marching Squares algorithm.
Marching Squares
For each 2x2 cell of the raster, the algorithm checks which corners are above and which are below the contour level. There are 16 possible configurations (2^4 corners), each producing zero, one or two line segments. The segments are then stitched together along cell edges to form continuous polylines.
Linear Interpolation
Where a contour crosses a cell edge, the exact crossing point is computed by linear interpolation between the two corner values. This makes contours appear smooth even when the underlying grid is coarse β at the cost of an idealised "slope is constant within a cell" assumption that does not always hold for real terrain.
Multiple Contour Levels
The algorithm runs once per requested elevation level. Specifying a contour interval of 10 m on a DEM ranging 0-3000 m produces 301 contour lines. Each line is tagged with its elevation in an attribute called ELEV or level.
Topology and Closing
Most algorithms close contours that touch the raster edge by snapping to the boundary. Closed contours always have a higher elevation inside (peaks) or lower (sinks).
Key Parameters and Options
Contour Interval
The vertical spacing between adjacent contours. The single most important parameter. Standard values:
- 1-5 m for large-scale engineering maps and Lidar-derived DTMs
- 10-20 m for hiking maps at 1:25,000 to 1:50,000
- 50-100 m for regional maps at 1:100,000 to 1:250,000
- 200-500 m for continental overviews
A bad interval choice produces either an overcrowded mess (too small) or a featureless map (too large).
Base Contour
The reference elevation that all other contours are anchored to. Defaults to 0 (sea level), so contours fall on multiples of the interval (0, 10, 20, 30...). Setting a non-zero base shifts the entire set.
Index Contours
Every fifth contour is conventionally drawn thicker and labelled β these are "index contours". The tool can flag every Nth contour with an index = true attribute.
Smoothing
Marching squares produces angular, jagged contours that follow the rectilinear pixel grid. Optional smoothing (Bezier or Chaikin) softens the lines for cartographic output. Smoothing displaces vertices slightly, so do not smooth before measuring length or area.
Minimum Length / Vertex Filter
Short isolated contours from small islands or noise can clutter a map. The tool can drop contours below a minimum length or vertex count.
Output Format
The tool exports GeoJSON, Shapefile, KML or GeoPackage.
Practical Applications
Topographic Mapping
Cartographers generate contours from a DEM as the foundation of any topographic basemap. Combined with shaded relief, hypsometric tints and feature labels, contours produce the iconic look of national topographic series like USGS topo, OS Explorer and Swisstopo.
Hiking and Outdoor Recreation
Trail maps, ski piste maps and paddling guides all need contours so users can read terrain steepness at a glance. A 10-20 m interval is typical for hiking maps.
Civil Engineering and Surveying
Site plans for roads, dams, pipelines and buildings include contours at 0.5-1 m intervals from a high-resolution Lidar or photogrammetric DEM. Volumetric calculations for cut-and-fill use the contour spacing to estimate slopes.
Hydrology and Floodplain Mapping
Bathymetric contours from sonar or Lidar reveal channel morphology, scour pools, sand bars and flood storage capacity. Contour maps of flood depth raster outputs communicate inundation extent intuitively.
Atmospheric and Climate Mapping
Weather maps use isobars (atmospheric pressure contours), isotherms (temperature) and isohyets (precipitation). Climate scientists generate long-term mean contours for regional assessments.
Geophysical Exploration
Geophysicists contour gravity, magnetic and radiometric data to highlight subsurface structures. Closed contours often indicate orebodies or basement highs.
Bathymetry and Marine Charts
Nautical charts contour depth in metres or fathoms. Critical for navigation, scuba diving and habitat mapping.
Step-by-Step Workflow in gis.tools
- Open the Raster to Contours page on gis.tools.
- Drag a single-band raster GeoTIFF β typically a DEM, but any continuous surface works β into the page. The file is decoded with
geotiff.js. - The tool reads the value range and suggests a contour interval. Override it if you have a target cartographic scale in mind.
- Set the base contour (default 0), the interval, and any minimum length filter.
- Optionally enable index contour flagging (every Nth line).
- Optionally enable smoothing for cartographic output.
- Click Generate. Marching squares runs over the entire raster.
- Preview the contours on the map. Toggle index lines, adjust styling, and use Label Placement Tool for elevation labels.
- Export as GeoJSON, KML, Shapefile or GeoPackage.
Worked Example: 10 m Contours from a 30 m SRTM Tile
You download an SRTM 30 m DEM tile covering the Pyrenees, ranging 200-3400 m. You drop it into the Raster to Contours tool and ask for 50 m contours with a base of 0 and index every 5th line. After a couple of seconds the tool produces 65 contour lines tagged with elevations from 200 to 3400 m. Index contours at 250 m intervals are flagged for thicker rendering. You preview the result and note that the tight contour spacing on the north faces of Aneto and the Vignemale correctly reflects the steepness of those classic peaks. You export the contours as GeoJSON, then use Label Placement Tool to add elevation annotations and produce a print-ready map sheet via the Print Composer.
Common Pitfalls and Gotchas
- Choosing too small an interval on a noisy DEM produces a tangled mess of micro-contours that obscure the real terrain. Smooth or aggregate the DEM first.
- Choosing too large an interval erases real detail β flat plateaus may have only one or two contour lines.
- Stair-stepping artefacts in coarse DEMs make contours unnaturally angular. Bezier or Chaikin smoothing helps but introduces bias.
- Pits and sinks in unfilled DEMs produce closed concentric contours that look like miniature craters; fill the DEM first if these are artefacts.
- Contours generated from a DEM in a geographic CRS (degrees) will have correct elevations but distorted spacing β reproject to a projected CRS first.
- Marching squares cannot represent saddles unambiguously; the tool uses a deterministic tie-break rule.
- Very large rasters can produce millions of segments that exceed browser memory; downsample first.
- Smoothed contours should not be used for length, slope or area measurements β they no longer match the grid.
Tips for Best Results
- Match the contour interval to your map scale and the DEM resolution. A 1 m DTM can support 0.5 m contours; a 30 m DEM should not.
- Reproject the DEM to a metric projected CRS before contouring so the line spacing is geometrically meaningful.
- Always inspect the histogram of the input raster to confirm the value range and choose a reasonable interval.
- Use index contours (every 5th line) for legibility on printed maps.
- Smooth contours only for cartographic display, never for analysis.
- Filter out micro-contours below a minimum length to declutter the map.
- For bathymetric contours use a negative interval below sea level if your raster encodes depth as negative values.
- Pair contours with a Hillshade Generator for the best topographic look.
Comparison with Other GIS Approaches
GDAL's gdal_contour -a ELEV -i 10 input.tif output.shp is the canonical command-line implementation. ArcGIS Spatial Analyst's Contour and Contour List tools wrap the same algorithm. QGIS exposes both the GDAL and the GRASS r.contour tools. The Raster to Contours tool on gis.tools delivers the same Marching Squares output in the browser. The trade-off is memory: very large DEMs (multi-gigabyte) should be processed offline with GDAL or rasterio, but for tile-sized inputs the browser approach is fast and convenient.
Performance Considerations
Marching squares is O(n) in pixel count, plus a constant-factor cost per output segment. A 4000x4000 DEM with a moderate contour interval generates tens of thousands of segments in 1-3 seconds. Very fine intervals can produce millions of segments and overwhelm browser memory; clip to your AOI first with Clip Raster by Polygon or downsample with Raster Resampler.
Data Privacy and Browser-Based Processing
Your DEM is read with the File API, decoded by geotiff.js, processed by a JavaScript Marching Squares implementation and exported via a download blob. No upload, no telemetry, no logging of file metadata. This is essential for proprietary Lidar acquisitions, sensitive bathymetric surveys, classified terrain data and any workflow with data residency restrictions.
Related GIS Concepts
Isolines vs Contours: Same concept β "isolines" is the generic term, "contours" is its topographic specialisation.
Hypsometric Tinting: Colouring elevations along a continuous ramp; complements contours in cartographic output.
Saddle Ambiguity: A 2x2 cell with diagonal corners above and below the contour level has two valid topological interpretations. Marching Squares uses a deterministic rule to choose one.
Smoothing Algorithms: Chaikin, Bezier and B-spline smoothing soften jagged contour lines for visual output.
Indexed Contours: Every Nth contour drawn thicker and labelled, by long-standing cartographic convention.
Frequently Asked Questions
How do I pick a good contour interval?
Match it to your map scale and the smoothness of the terrain. For a 1:50,000 hiking map use 20 m. For 1:10,000 engineering maps use 1-2 m.
Can I contour something other than elevation?
Yes β any continuous raster works: temperature, precipitation, NDVI, gravity, distance, water depth.
Are contours generated as polygons or lines?
Lines. To get polygons between adjacent contours (filled contours), use a separate "filled contour" tool or convert with a polygonisation step.
Do contours include elevation labels?
The line features are tagged with the elevation in an attribute, but rendering text on top of the lines is a separate cartographic step β see Label Placement Tool.
Can I export contours as a Shapefile?
Yes β GeoJSON, KML, Shapefile and GPKG are all supported export formats.
Why do my contours look jagged?
Marching squares produces grid-aligned segments. Apply Chaikin or Bezier smoothing for cartographic display.
Related Tools on gis.tools
Related Tools
View All ToolsRaster Reclass Tool
Reclassify raster values based on custom rules
Raster ToolsNDVI Calculator
Calculate vegetation index from multispectral imagery
Raster ToolsClip Raster by Polygon
Clip raster data to a polygon boundary
Raster ToolsRaster Mosaic Preview
Preview multiple raster tiles as a single view
Raster ToolsHillshade Generator
Generate shaded relief from a DEM GeoTIFF
Raster ToolsRaster to Points
Sample raster values to a point grid
Raster Tools100% client-side processing - your data stays private and never leaves your device