ST_Value

更新时间:
复制 MD 格式

Returns the pixel value at a given location in a raster band. Specify the location by column and row number or by x and y coordinates. When exclude_nodata is true (the default), NoData pixels return NULL.

Syntax

float8 ST_Value(raster raster_obj,
        integer band,
        integer column_sn,
        integer row_sn,
        boolean exclude_nodata default true);

float8 ST_Value(raster raster_obj,
        integer band,
        float8  x,
        float8  y,
        boolean exclude_nodata default true);

Parameters

ParameterTypeDescription
raster_objrasterThe raster object to query.
bandintegerThe band to read from. Band numbers start at 0.
column_snintegerThe column number of the target pixel, measured from the upper-left corner of the raster.
row_snintegerThe row number of the target pixel, measured from the upper-left corner of the raster.
xfloat8The x coordinate of the target pixel.
yfloat8The y coordinate of the target pixel.
exclude_nodatabooleanSpecifies whether to exclude NoData pixels. When true, NoData pixels return NULL. Default: true.

Usage notes

  • Band numbering starts at 0. The first band is band 0, the second is band 1, and so on.

  • Column and row numbers are measured from the upper-left corner of the raster object.

Examples

Query by column and row number

Returns the pixel value at column 10, row 20 of band 0. NoData pixels return NULL (default behavior).

SELECT ST_Value(rast_obj, 0, 10, 20)
FROM raster_table
WHERE id = 1;

Result:

169

Query by coordinates with NoData included

Returns the pixel value at coordinates (150.0, 20.0) in band 0. Setting exclude_nodata to false returns the raw value even if the pixel is NoData.

SELECT ST_Value(rast_obj, 0, 150::float8, 20::float8, false)
FROM raster_table
WHERE id = 3;

Result:

77