Skip to content

RS_SetValue

Returns the raster with one pixel of a band set to a new value.

Usage

raster RS_SetValue(rast: raster, col_x: integer, row_y: integer, new_value: double)
raster RS_SetValue(rast: raster, band: integer, col_x: integer, row_y: integer, new_value: double)

Arguments

  • rast (raster): Input raster
  • band (integer): Band index (1-based). When omitted, the raster must have a single band; on a multiband raster the band has to be given.
  • col_x (integer): Column of the pixel (1-based).
  • row_y (integer): Row of the pixel (1-based).
  • new_value (double): The value to store.

Description

col_x and row_y count from 1, as in PostGIS and Sedona Spark: (1, 1) is the upper-left pixel. The pixel is overwritten even if it holds the band’s nodata value, and the band’s nodata value is unchanged.

The value is stored in the band’s pixel type: an integer band truncates it toward zero (3.9 is stored as 3) and a float32 band rounds it to the nearest float32. A value outside an integer band’s range (for a 64-bit integer band, beyond ±2^53, the largest integers a double holds exactly), NaN, a pixel outside the grid, or a band the raster does not have is an error. Only 2-D rasters are supported.

Examples

Setting pixel (2, 2) of band 1 to 42 raises the band’s maximum, which is otherwise 1, to 42:

SELECT RS_SummaryStats(RS_SetValue(RS_Example(), 1, 2, 2, 42), 'max', 1);
┌──────────────────────────────────────────────────────────────────────────────┐
│ rs_summarystats(rs_setvalue(rs_example(),Int64(1),Int64(2),Int64(2),Int64(42 │
│                           )),Utf8("max"),Int64(1))…                          │
╞══════════════════════════════════════════════════════════════════════════════╡
│                                                                         42.0 │
└──────────────────────────────────────────────────────────────────────────────┘