All Products
Search
Document Center

ApsaraDB RDS:ST_Contour

Last Updated:Mar 28, 2026

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

Syntax

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

Parameters

ParameterDescription
rastThe raster object. Must be a DEM with exactly one band.
bandThe band number. Starts from 0.
contourOptionsA JSON string that controls contour generation. See the fields below.

contourOptions fields

FieldTypeDefaultDescription
level_basefloat0.0The starting offset for contour values. For example, with level_base=5 and interval=10, contours are generated at 5, 15, 25, and so on.
fixed_levelfloat arrayNoneAn explicit list of contour values (e.g., [100, 200, 300]). When specified, interval is ignored.
intervalfloatNoneThe spacing between contours. Used only when fixed_level is not specified.
polygonizeboolfalseThe output type. false returns each contour as a closed curve. true fills the area between adjacent contours with DEM values and returns polygons.
nodatafloat-1.0The nodata value.

Description

ST_Contour processes the specified raster band and returns a set of records — one per contour line or filled polygon.

Choosing between `fixed_level` and `interval`: Use fixed_level to generate contours at exact elevations (e.g., [100, 200, 500]). Use interval for evenly spaced contours across the full elevation range. If both are specified, fixed_level takes precedence and interval is ignored.

Each returned record contains the following fields:

FieldTypeDescription
idintegerThe sequence number of the contour line or polygon.
min_valuefloatThe minimum DEM value in the contour line or polygon. For a DEM input, this is the lower elevation bound of that contour band.
max_valuefloatThe maximum DEM value in the contour line or polygon. For a DEM input, this is the upper elevation bound of that contour band.
geomgeometryThe geometry of the contour line or polygon.

Examples

Generate contour lines at a fixed interval

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

Generate filled polygons at specific elevations

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

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