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

Stack a given array of rasters into a single raster. The rasters are stacked in the order they are provided in the array. The function also explodes the stacked raster into multiple tiles.

This function handles rasters that are not aligned and having different resolutions, data types and coordinate reference systems:

* The CRS and resolution of the output raster will be the same as the selected reference raster.
* The data type of the output raster will be the most precise data type among all stacked bands.

## Signatures

```sql theme={"system"}
RS_StackTileExplode(rasters: Array[Raster], refRasterIndex: Integer, tileWidth: Integer, tileHeight: Integer, padWithNoData: Boolean = false, noDataValue: Double = NaN)
```

## Parameters

<ParamField body="rasters" type="Array[Raster]" required>
  An array of rasters to be stacked.
</ParamField>

<ParamField body="refRasterIndex" type="Integer" required>
  The zero-based index of the reference raster in the array of rasters. The CRS and resolution of the output raster will be the same as the reference raster. If `refRasterIndex` is -1, the last raster in the array will be used as the reference raster.
</ParamField>

<ParamField body="tileWidth" type="Integer" required>
  The width of the tiles in the output raster.
</ParamField>

<ParamField body="tileHeight" type="Integer" required>
  The height of the tiles in the output raster.
</ParamField>

<ParamField body="padWithNoData" type="Boolean" default="false">
  A boolean flag to determine whether to pad the output raster with no data values. If `padWithNoData` is true, the output raster will be padded with `noDataValue`.
</ParamField>

<ParamField body="noDataValue" type="Double" default="NaN">
  The no data value to use when padding the output raster.
</ParamField>

## Return type

<ResponseField type="Struct<x: Integer, y: Integer, tile: Raster>">
  A struct containing the result fields.
</ResponseField>

## Example

```sql theme={"system"}
SELECT RS_StackTileExplode(ARRAY(RS_FromPath('/path/to/raster1.tif'), RS_FromPath('/path/to/raster2.tif')), 0, 100, 100, true, 255)
```

```
+---+---+--------------------+
|  x|  y|                tile|
+---+---+--------------------+
|  0|  0|GridCoverage2D["g...|
|  1|  0|GridCoverage2D["g...|
|  2|  0|GridCoverage2D["g...|
|  0|  1|GridCoverage2D["g...|
|  1|  1|GridCoverage2D["g...|
|  2|  1|GridCoverage2D["g...|
|  0|  2|GridCoverage2D["g...|
|  1|  2|GridCoverage2D["g...|
|  2|  2|GridCoverage2D["g...|
+---+---+--------------------+
```
