Skip to main content
Returns a raster by replacing the values of pixels in a specified rectangular region or within a geometry. The top left corner of the region is defined by the colX and rowY coordinates. The width and height parameters specify the dimensions of the rectangular region. The new values to be assigned to the pixels in this region can be specified as an array passed to this function.
Since v1.5.1, if the coordinate reference system (CRS) of the input geom geometry differs from that of the raster, then geom will be transformed to match the CRS of the raster. If the raster or geom doesn’t have a CRS then it will default to 4326/WGS84.

Signatures

RS_SetValues(raster: Raster, bandIndex: Integer, colX: Integer, rowY: Integer, width: Integer, height: Integer, newValues: ARRAY[Double], keepNoData: Boolean = false)
RS_SetValues(raster: Raster, bandIndex: Integer, colX: Integer, rowY: Integer, width: Integer, height: Integer, newValues: ARRAY[Double])
RS_SetValues(raster: Raster, bandIndex: Integer, geom: Geometry, newValue: Double, allTouched: Boolean = false, keepNoData: Boolean = false)
RS_SetValues(raster: Raster, bandIndex: Integer, geom: Geometry, newValue: Double, allTouched: Boolean = false)
RS_SetValues(raster: Raster, bandIndex: Integer, geom: Geometry, newValue: Double)

Parameters

raster
Raster
required
The input raster.
bandIndex
Integer
required
The 1-indexed band to modify.
colX
Integer
required
The column index of the top-left corner of the rectangular region.
rowY
Integer
required
The row index of the top-left corner of the rectangular region.
width
Integer
required
The width of the rectangular region in pixels.
height
Integer
required
The height of the rectangular region in pixels.
newValues
ARRAY[Double]
required
An array of new pixel values to assign to the rectangular region.
geom
Geometry
required
The geometry defining the region of interest (ROI) for pixel replacement.
newValue
Double
required
The new value to assign to pixels within the geometry ROI.
allTouched
Boolean
Whether to include all pixels touched by the geometry, not just those whose center is within it. Defaults to false.
keepNoData
Boolean
Whether to preserve existing NoData values in the region. Defaults to false.
If the shape of newValues doesn’t match with provided width and height, IllegalArgumentException is thrown.
If the mentioned bandIndex doesn’t exist, this will throw an IllegalArgumentException.

Return type

The resulting raster.

Examples

Rectangular region

SELECT RS_BandAsArray(
        RS_SetValues(
            RS_AddBandFromArray(
                RS_MakeEmptyRaster(1, 5, 5, 0, 0, 1, -1, 0, 0, 0),
                Array(1,1,1,0,0,0,1,2,3,3,5,6,7,0,0,3,0,0,3,0,0,0,0,0,0), 1, 0d
                ),
            1, 2, 2, 3, 3, [11,12,13,14,15,16,17,18,19]
            )
        )
Array(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 11.0, 12.0, 13.0, 3.0, 5.0, 14.0, 15.0, 16.0, 0.0, 3.0, 17.0, 18.0, 19.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

Geometry ROI

SELECT RS_BandAsArray(
        RS_SetValues(
            RS_AddBandFromArray(
                RS_MakeEmptyRaster(1, 5, 5, 1, -1, 1, -1, 0, 0, 0),
                Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), 1
                ),
            1, ST_GeomFromWKT('POLYGON((1 -1, 3 -3, 6 -6, 4 -1, 1 -1))'), 255, false, false
            )
           )
Array(255.0, 255.0, 255.0, 0.0, 0.0, 0.0, 255.0, 255.0, 255.0, 0.0, 0.0, 0.0, 255.0, 255.0, 0.0, 0.0, 0.0, 0.0, 255.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)