All Products
Search
Document Center

PolarDB:ST_AddZ

Last Updated:Mar 28, 2026

Sets the Z coordinate of each point on a geometry to the pixel value read from a raster band.

Syntax

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

Parameters

ParameterDescriptionDefault
sourceThe raster from which the geometry is converted.
geomThe geometry whose Z coordinate you want to set.
pyramidThe pyramid level of the raster. Valid values start from 0.0
bandThe band index of the raster. Valid values start from 0.0

Description

ST_AddZ specifies the Z coordinate of a geometry based on the band of the raster converted from the geometry. The coordinate type of the result depends on whether the raster is georeferenced:

  • Georeferenced raster: returns geographic coordinates.

  • Non-georeferenced raster: returns pixel coordinates.

Note All points on the geometry must fall within the raster.

Examples

Example 1: Default pyramid level and band

Query a point at pyramid level 0, band 0.

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

Result:

POINT Z(120.5 30.6 27)

Example 2: Higher pyramid level and different band

Query the same point at pyramid level 1, band 1.

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

Result:

POINT Z(120.5 30.6 115)