This function specifies the Z coordinate of a geometry based on the band of the raster that is converted from the geometry.

Syntax

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

Parameters

ParameterDescription
sourceThe raster from which the geometry is converted.
geomThe geometry whose Z coordinate you want to specify.
pyramidThe pyramid level of the raster. Valid values start from 0. If the number of layers in the pyramid is N, the value of this parameter is an integer that ranges from 0 to the difference between N and 1. Default value: 0.
bandThe band of the raster. Valid values start from 0. If the number of bands of the raster is N, the value of this parameter is an integer that ranges from 0 to the difference between N and 1. Default value: 0.

Description

This function specifies the Z coordinate of a geometry based on the band of the raster that is converted from the geometry. If the raster is georeferenced, this function returns a geographic coordinate of the geometry. If the raster is not georeferenced, this function returns a pixel coordinate of the geometry.

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

Examples

DO $$
declare
    rast raster;
begin
    select raster_obj into rast from raster_table where id = 1;
    SELECT ST_AddZ(rast, ST_GeomFromText('POINT(120.5 30.6)', 4326), 0, 0);
end;    
$$ LANGUAGE 'plpgsql';