gdal_contour
Generate contour lines from raster data
TLDR
Create a vector dataset with contour lines spread over an 100-meter [i]nterval while [a]ttributing the elevation property as "ele"
Create a vector dataset with [p]olygons spread over an 100-meter [i]nterval
SYNOPSIS
gdal_contour
[-b <band>]
[-a <attribute_name>]
[-3d]
[-i <interval>]
[-f <format_name>]
[-nln <layer_name>]
[-s <smooth_points>]
[-snodata <value>]
[-v]
[-q]
[-<output_format_option> <value>]
<src_filename> <dst_filename>
PARAMETERS
-b <band>
Selects the input raster band to read. Defaults to band 1.
-a <attribute_name>
Specifies the name of an attribute field to be added to the contour lines, storing the elevation value for each contour.
-3d
Forces the output contour lines to be 3D, including the Z coordinate derived from the elevation.
-i <interval>
Defines the contour interval in ground units (e.g., meters or feet). This is a mandatory parameter for contour generation.
-f <format_name>
Specifies the output vector format name (e.g., ESRI Shapefile, GPKG, GeoJSON). If not specified, GDAL attempts to guess the format from the destination filename extension.
-nln <layer_name>
Assigns a specific name to the output layer within the destination vector dataset.
-s <smooth_points>
Adds a specified number of intermediate points to smooth the generated contour lines. Higher values result in smoother lines but may increase processing time and file size.
-snodata <value>
Specifies an input pixel value to treat as no data. Pixels with this value will be ignored during contour generation.
-v
Enables verbose output, displaying progress messages and additional information during processing.
-q
Suppresses progress messages and other non-essential output, useful for scripting.
-<output_format_option> <value>
Allows passing format-specific creation options for the output dataset. These options vary by vector format.
<src_filename>
The path to the input raster file (Digital Elevation Model) from which contours will be generated.
<dst_filename>
The path to the output vector file where the generated contour lines will be saved.
DESCRIPTION
gdal_contour is a GDAL utility that generates vector contour lines from a raster Digital Elevation Model (DEM). It reads a single-band raster image and outputs a vector dataset (e.g., Shapefile, GeoPackage, GeoJSON) containing contour lines as polygons or lines. The contours represent points of equal elevation, making it a fundamental tool in GIS for terrain analysis. Users can specify the contour interval, a base contour level, and optionally an attribute field to store the elevation value. The command is widely used for hydrological analysis, terrain visualization, and engineering applications to delineate elevation breaks. It leverages GDAL's robust I/O capabilities, supporting numerous raster and vector formats for input and output respectively.
CAVEATS
The accuracy of generated contours depends on the resolution and quality of the input DEM. Smoothing with the -s option can visually improve contours but might slightly deviate them from exact elevation values or introduce artifacts. Processing very large raster datasets can be computationally intensive and require significant memory.
EXAMPLES
To generate contours at 10-unit intervals from input.tif to output.shp, with elevation values stored in an attribute field named ELEV:gdal_contour -i 10 -a ELEV input.tif output.shp
To create smoothed contours at 5-unit intervals and save them in GeoPackage format:gdal_contour -i 5 -s 3 -f GPKG input.tif output.gpkg
HISTORY
gdal_contour is a core utility within the GDAL (Geospatial Data Abstraction Library) suite, which was initially developed by Frank Warmerdam and first released in 1998. It has evolved alongside GDAL, continually benefiting from improved performance, extended format support, and bug fixes, establishing itself as a standard tool for creating vector contours from raster elevation data in GIS workflows.