All Products
Search
Document Center

PolarDB:ST_Contour

Last Updated:Mar 28, 2026

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

Syntax

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

Parameters

ParameterDescription
rastThe raster object. Must be a single-band DEM.
bandThe band index. Starts from 0.
contourOptionsA JSON string that controls contour generation. See the following table for supported fields.

contourOptions fields

FieldTypeDefaultDescription
level_basefloat0.0The starting elevation for contour generation.
fixed_levelfloat arrayNoneAn array of specific elevation values at which to generate contours. When specified, interval is ignored.
intervalfloatNoneThe elevation difference between consecutive contour lines.
polygonizebooleanfalseThe output type. false: returns each contour as a closed curve. true: fills the area between consecutive contours with DEM values and returns a polygon.
nodatafloat-1.0The nodata value.

Description

ST_Contour generates contours from a raster object based on the specified band. The input raster must be a single-band DEM.

Parameter priority: If fixed_level is specified, interval is ignored. Use fixed_level when you need contours at specific elevation values; use interval for evenly spaced contours.

The function returns a set of records. Each record contains the following fields:

FieldDescription
idThe sequence number of the contour line or polygon.
min_valueThe minimum value in the contour line or polygon.
max_valueThe maximum value in 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 closed contour lines, one for every 2.0 units of elevation.

select (ST_Contour(rast,0,'{"interval":"2.0"}')).* from raster_table where id =1;

Generate filled polygons at specific elevation levels

Returns polygons that fill the areas between the specified elevation thresholds: 1, 5, 10, 15, 20, and 30. Each record includes the min_value and max_value of its elevation band.

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 handling

Returns polygons at 5-unit intervals starting from elevation 1.0, excluding pixels with a nodata value of 0.0.

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