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
| Parameter | Description | Default |
|---|---|---|
source | The raster from which the geometry is converted. | — |
geom | The geometry whose Z coordinate you want to set. | — |
pyramid | The pyramid level of the raster. Valid values start from 0. | 0 |
band | The 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)