All Products
Search
Document Center

PolarDB:ST_AddZ

Last Updated:Mar 28, 2026

Assigns a Z coordinate to a geometry based on raster band values.

Syntax

geometry ST_AddZ(raster source,
                 geometry geom,
                 integer pyramid,
                 integer band);

Parameters

ParameterDescription
sourceThe source raster.
geomThe geometry to assign a Z coordinate to.
pyramidThe pyramid level of the raster. Valid values start from 0. Default value: 0.
bandThe raster band to read values from. Valid values start from 0. Default value: 0.

Description

ST_AddZ reads pixel values from the specified band and pyramid level of a raster, then sets those values as the Z coordinate of the input geometry.

  • If the raster is georeferenced, the function returns a geographic coordinate.

  • If the raster is not georeferenced, the function returns a pixel coordinate.

Note All points in the geometry must fall within the raster bounds.

Examples

Query the Z coordinate from pyramid level 0, band 0:

SELECT ST_AddZ(rast_object, ST_GeomFromText('POINT(120.5 30.6)', 4326), 0, 0)
FROM raster_table;

Output:

POINT Z(120.5 30.6 27)

Query the Z coordinate from pyramid level 1, band 1:

SELECT ST_AddZ(rast_object, ST_GeomFromText('POINT(120.5 30.6)', 4326), 1, 1)
FROM raster_table;

Output:

POINT Z(120.5 30.6 115)