Sets the pixel value of a raster object at a specified location, identified either by row and column coordinates or by a geometry region.
Syntax
raster ST_SetValue(raster raster_obj,
integer row,
integer column,
double value,
integer band);
raster ST_SetValue(raster raster_obj,
geometry geom,
double value,
integer band default 0,
boolean rebuild_pyd default true,
cstring setvalueOptions default '');Parameters
| Parameter | Description |
|---|---|
| raster_obj | The raster object to update. |
| row | The row number of the pixel to update. |
| column | The column number of the pixel to update. |
| value | The new pixel value. |
| band | The band number of the pixel to update. |
| geom | The geometry object that defines the region in which pixel values are updated. |
| rebuild_pyd | Specifies whether to rebuild the pyramid after the update. Default value: true. |
| setvalueOptions | Additional options for the update operation, specified as a JSON string. For details, see the setvalueOptions fields table below. Default value: '' (empty string). |
setvalueOptions fields
| Field | Type | Default value | Description |
|---|---|---|---|
| window_clip | bool | false | Specifies whether to use the bounding box of the geometry object to define the update region. If set to true, the minimum bounding rectangle (MBR) of the geometry object is used as the update region. If set to false, the geometry object itself is used as the update region. |
| rast_coord | bool | false | Specifies whether the input geometry uses pixel coordinates. If set to true, the x-coordinate specifies the column number of a pixel and the y-coordinate specifies the row number, with valid values starting from 0. If set to false, pixel coordinates are not used. |
Examples
The following example reads the current pixel value at row 0, column 2, band 1 before updating it.
select st_value(rast, 0, 2, 1) from raster_table order by id;The following example sets pixel values to 250.0 for all pixels that fall within the MULTIPOINT geometry on band 0. The pyramid is rebuilt after the update.
update raster_table set rast=st_setvalue(rast, ST_GeomFromText('MULTIPOINT(0 0, 2 2, 10 10)', 4326),250.0, 0, true);The following example sets pixel values to 10.0 along a LINESTRING path using pixel coordinates (rast_coord: true). The geometry coordinates are interpreted as column and row numbers rather than geographic coordinates.
update raster_table set rast=st_setvalue(rast, ST_GeomFromText('LINESTRING(211 77, 233 100)', 4326), 10.0, 0, false, '{"rast_coord":true}');