> ## 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_AddBand

Adds a new band to a raster `toRaster` at a specified index `toRasterIndex`. The new band's values are copied from `fromRaster` at a specified band index `fromBand`.
If no `toRasterIndex` is provided, the new band is appended to the end of `toRaster`. If no `fromBand` is specified, band `1` from `fromRaster` is copied by default.

<Note>
  IllegalArgumentException will be thrown in these cases:

  * The provided Rasters, `toRaster` & `fromRaster` don't have same shape.
  * The provided `fromBand` is not in `fromRaster`.
  * The provided `toRasterIndex` is not in or at end of `toRaster`.
</Note>

## Signatures

```sql theme={"system"}
RS_AddBand(toRaster: Raster, fromRaster: Raster, fromBand: Integer = 1, toRasterIndex: Integer = at_end)
```

```sql theme={"system"}
RS_AddBand(toRaster: Raster, fromRaster: Raster, fromBand: Integer = 1)
```

```sql theme={"system"}
RS_AddBand(toRaster: Raster, fromRaster: Raster)
```

## Parameters

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

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

<ParamField body="fromBand" type="Integer" default="1">
  The band index to copy from the source raster.
</ParamField>

<ParamField body="toRasterIndex" type="Integer" default="at_end">
  The index in the target raster to insert the band.
</ParamField>

## Return type

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

## Example

```sql theme={"system"}
SELECT RS_AddBand(raster1, raster2, 2, 1) FROM rasters
```

```
GridCoverage2D["g...
```
