This topic describes the ST_SetValue function. This function changes the pixel value based on a geometry or the row and column of a raster.

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 specified raster object.
row The row number of the pixel value that is changed.
column The column number of the pixel value that is changed.
value The new pixel value.
band The band number of the pixel value that is changed.
rebuild_pyd Specifies whether to rebuild the pyramid.
setvalueOptions The change options of a pixel value. The value of this parameter is a JSON string. For more information, see Table 1.
Table 1. Fields in the setvalueOptions parameter
Field Type Default value Description
window_clip bool false Specifies whether to use the bounding box of the geometry object to clip the raster object.
  • true: uses the minimum bounding rectangle (MBR) of the geometry object as the region for changing the pixel value.
  • false: uses the geometry object as the region for changing the pixel value.
rast_coord bool false Specifies whether the input geometry uses pixel coordinates.
  • true: Pixel coordinates are used. The x-coordinate specifies the column number of a pixel and the y-coordinate specifies the row number of a pixel. The valid values of the x-coordinate and y-coordinate start from 0.
  • false: Pixel coordinates are not used.

Examples

select st_value(rast, 0, 2, 1) from raster_table order by id;

update raster_table set rast=st_setvalue(rast, ST_geomfromtext('MULTIPOINT(0 0, 2 2, 10 10)', 4326),250.0, 0, true);

update raster_table set rast=st_setvalue(rast, ST_geomfromtext('LINESTRING(211 77, 233 100)', 4326), 10.0, 0, false, '{"rast_coord":true}');