All Products
Search
Document Center

PolarDB:ST_SetValue

Last Updated:Mar 28, 2026

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

ParameterDescription
raster_objThe raster object to update.
rowThe row number of the pixel to update.
columnThe column number of the pixel to update.
valueThe new pixel value.
bandThe band number of the pixel to update.
geomThe geometry object that defines the region in which pixel values are updated.
rebuild_pydSpecifies whether to rebuild the pyramid after the update. Default value: true.
setvalueOptionsAdditional options for the update operation, specified as a JSON string. For details, see the setvalueOptions fields table below. Default value: '' (empty string).

setvalueOptions fields

FieldTypeDefault valueDescription
window_clipboolfalseSpecifies 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_coordboolfalseSpecifies 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}');