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
| Parameter | Type | Description |
|---|---|---|
raster_obj | raster | The raster object to query. |
band | integer | The band to read from. Band numbers start at 0. |
column_sn | integer | The column number of the target pixel, measured from the upper-left corner of the raster. |
row_sn | integer | The row number of the target pixel, measured from the upper-left corner of the raster. |
x | float8 | The x coordinate of the target pixel. |
y | float8 | The y coordinate of the target pixel. |
exclude_nodata | boolean | Specifies 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 band1, 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:
169Query 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该文章对您有帮助吗?