> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wherobots.com/llms.txt
> Use this file to discover all available pages before exploring further.

# RS_SetValues

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.

<Note>
  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`.
</Note>

## Signatures

```sql theme={"system"}
RS_SetValues(raster: Raster, bandIndex: Integer, colX: Integer, rowY: Integer, width: Integer, height: Integer, newValues: ARRAY[Double], keepNoData: Boolean = false)
```

```sql theme={"system"}
RS_SetValues(raster: Raster, bandIndex: Integer, colX: Integer, rowY: Integer, width: Integer, height: Integer, newValues: ARRAY[Double])
```

```sql theme={"system"}
RS_SetValues(raster: Raster, bandIndex: Integer, geom: Geometry, newValue: Double, allTouched: Boolean = false, keepNoData: Boolean = false)
```

```sql theme={"system"}
RS_SetValues(raster: Raster, bandIndex: Integer, geom: Geometry, newValue: Double, allTouched: Boolean = false)
```

```sql theme={"system"}
RS_SetValues(raster: Raster, bandIndex: Integer, geom: Geometry, newValue: Double)
```

## Parameters

<ParamField body="raster" type="Raster" required>
  The input raster.
</ParamField>

<ParamField body="bandIndex" type="Integer" required>
  The 1-indexed band to modify.
</ParamField>

<ParamField body="colX" type="Integer" required>
  The column index of the top-left corner of the rectangular region.
</ParamField>

<ParamField body="rowY" type="Integer" required>
  The row index of the top-left corner of the rectangular region.
</ParamField>

<ParamField body="width" type="Integer" required>
  The width of the rectangular region in pixels.
</ParamField>

<ParamField body="height" type="Integer" required>
  The height of the rectangular region in pixels.
</ParamField>

<ParamField body="newValues" type="ARRAY[Double]" required>
  An array of new pixel values to assign to the rectangular region.
</ParamField>

<ParamField body="geom" type="Geometry" required>
  The geometry defining the region of interest (ROI) for pixel replacement.
</ParamField>

<ParamField body="newValue" type="Double" required>
  The new value to assign to pixels within the geometry ROI.
</ParamField>

<ParamField body="allTouched" type="Boolean">
  Whether to include all pixels touched by the geometry, not just those whose center is within it. Defaults to `false`.
</ParamField>

<ParamField body="keepNoData" type="Boolean">
  Whether to preserve existing NoData values in the region. Defaults to `false`.
</ParamField>

<Note>
  If the shape of `newValues` doesn't match with provided `width` and `height`, `IllegalArgumentException` is thrown.
</Note>

<Note>
  If the mentioned `bandIndex` doesn't exist, this will throw an `IllegalArgumentException`.
</Note>

## Return type

<ResponseField type="Raster">
  The resulting raster.
</ResponseField>

## Examples

### Rectangular region

```sql theme={"system"}
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

```sql theme={"system"}
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)
```
