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
| Parameter | Description |
|---|---|
source | The source raster. |
geom | The geometry to assign a Z coordinate to. |
pyramid | The pyramid level of the raster. Valid values start from 0. Default value: 0. |
band | The 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)