Sets the pixel value of a raster object at a specified location, identified either by row and column or by a geometry shape.
Syntax
Overload 1: set by row and column
raster ST_SetValue(raster raster_obj,
integer row,
integer column,
double value,
integer band);Overload 2: set by geometry
raster ST_SetValue(raster raster_obj,
geometry geom,
double value,
integer band default 0,
boolean rebuild_pyd default true,
cstring setvalueOptions default '');Parameters
| Parameter | Type | Description |
|---|---|---|
raster_obj | raster | The raster object to update. |
row | integer | The row number of the pixel to update. |
column | integer | The column number of the pixel to update. |
value | double | The new pixel value. |
band | integer | The band number of the pixel to update. |
geom | geometry | The geometry that defines the region in which pixel values are updated. |
rebuild_pyd | boolean | Specifies whether to rebuild the pyramid after updating pixel values. |
setvalueOptions | cstring | Additional options for the update operation, passed as a JSON string. See the following table for supported fields. |
setvalueOptions fields
| Field | Type | Default | Description |
|---|---|---|---|
window_clip | bool | false | Specifies whether to use the bounding box of the geometry object as the update region. true uses the minimum bounding rectangle (MBR) of the geometry object. false uses the geometry object itself. |
rast_coord | bool | false | Specifies whether the input geometry uses pixel coordinates. true means pixel coordinates are used, where the x-coordinate maps to the column number and the y-coordinate maps to the row number, both starting from 0. false means pixel coordinates are not used. |
Examples
Read the pixel value at row 0, column 2, band 1:
SELECT ST_Value(rast, 0, 2, 1) FROM raster_table ORDER BY id;Set pixel values to 250.0 at the locations defined by a MULTIPOINT geometry on band 0, with pyramid rebuild enabled:
UPDATE raster_table
SET rast = ST_SetValue(rast, ST_GeomFromText('MULTIPOINT(0 0, 2 2, 10 10)', 4326), 250.0, 0, true);Set pixel values to 10.0 along a LINESTRING using pixel coordinates (rast_coord: true), without rebuilding the pyramid:
UPDATE raster_table
SET rast = ST_SetValue(rast, ST_GeomFromText('LINESTRING(211 77, 233 100)', 4326), 10.0, 0, false, '{"rast_coord":true}');