All Products
Search
Document Center

PolarDB:ST_Contour

Last Updated:Mar 28, 2026

Generates contour lines or filled contour polygons from a single-band digital elevation model (DEM) raster.

Syntax

set of record ST_Contour(
    raster rast,
    integer band,
    cstring contourOptions);

Parameters

ParameterTypeDescription
rastrasterThe raster object. Must be a single-band DEM.
bandintegerThe band number. Bands are zero-indexed, starting at 0.
contourOptionscstringA JSON string that controls how contours are generated. See the fields below.

contourOptions fields

FieldTypeDefaultDescription
level_basefloat0.0The base elevation from which contour intervals are calculated.
fixed_levelfloat arrayNoneAn explicit list of contour elevation values. When set to a non-empty array, interval is ignored.
intervalfloatNoneThe elevation difference between consecutive contour lines. Ignored when fixed_level is set.
polygonizeboolfalseThe output geometry type. false returns each contour as a closed curve. true fills the area between each pair of contours with DEM values and returns polygons.
nodatafloat-1.0The nodata value.

Return value

The function returns a set of records with the following fields:

FieldDescription
idThe sequence number of the contour line or polygon.
max_valueThe maximum DEM elevation within the contour line or polygon.
min_valueThe minimum DEM elevation within the contour line or polygon.
geomThe geometry object representing the contour line or polygon.

Examples

Generate contour lines at a fixed interval

Returns a set of contour lines spaced 2 elevation units apart.

SELECT (ST_Contour(rast, 0, '{"interval":"2.0"}')).*
FROM raster_table
WHERE id = 1;

Generate filled polygons at specific elevation levels

Returns polygons for the areas between the specified elevation thresholds.

SELECT (ST_Contour(rast, 0, '{"fixed_level":[1,5,10,15,20,30],"polygonize":"true"}')).*
FROM raster_table
WHERE id = 1;

Generate filled polygons with a custom base and nodata value

Returns polygons starting from elevation 1.0, spaced 5 units apart, treating 0.0 as nodata.

SELECT (ST_Contour(rast, 0, '{"interval":"5","nodata":"0.0","level_base":"1.0","polygonize":"true"}')).*
FROM raster_table
WHERE id = 1;