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

Parameters

Raster
required
The input raster.
Integer
required
The 1-indexed band to modify.
Integer
required
The column index of the top-left corner of the rectangular region.
Integer
required
The row index of the top-left corner of the rectangular region.
Integer
required
The width of the rectangular region in pixels.
Integer
required
The height of the rectangular region in pixels.
ARRAY[Double]
required
An array of new pixel values to assign to the rectangular region.
Geometry
required
The geometry defining the region of interest (ROI) for pixel replacement.
Double
required
The new value to assign to pixels within the geometry ROI.
Boolean
For polygon geometries, the allTouched parameter determines how pixels are selected:
  • When true, pixel selection also includes cells entered by the polygon’s boundary, following the RS_AsRaster rules.
  • When false (default), pixels whose centroid intersects the polygon will be included.
A polygon never selects a pixel it touches only on the pixel’s boundary, whichever edge that is. A polygon aligned with grid lines selects only pixels inside it.Point geometries select the single pixel containing the point under the half-open rule, regardless of allTouched. Line rasterization follows the cells entered by its segments rather than requiring a pixel-centre intersection. A point or line lying on an internal grid edge selects the pixel after it in pixel order; one lying on the raster’s last edge selects none. A neighboring pixel contacted only at a line endpoint is not selected unless the segment enters it.For LineString geometries, allTouched can also change the rasterization window at grid boundaries and therefore the selected pixels.
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

Geometry ROI