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

Computes zonal statistics for **all bands** of a raster in a single call, returning an array of structs. Each element in the array corresponds to one band and has the same schema as the struct returned by [RS\_ZonalStatsAll](/reference/wherobots-db/raster-data/band-accessors/RS_ZonalStatsAll):

* `count`: Count of the pixels.
* `sum`: Sum of the pixel values.
* `mean`: Arithmetic mean.
* `median`: Median.
* `mode`: Mode.
* `stddev`: Standard deviation.
* `variance`: Variance.
* `min`: Minimum value of the zone.
* `max`: Maximum value of the zone.

The `allTouched` parameter determines how pixels are selected:

* When `true`, any pixel touched by the geometry is included.
* When `false` (default), only pixels whose centroid intersects the geometry are included.

<img src="https://mintcdn.com/wherobots/zRR-WVX5Eck7133j/images/sql-functions/RS_ZonalStatsAllBands/RS_ZonalStatsAllBands.svg?fit=max&auto=format&n=zRR-WVX5Eck7133j&q=85&s=c9f3a193258ede0bb6fa4a2b25a4b4b5" alt="RS_ZonalStatsAllBands" width="780" height="440" data-path="images/sql-functions/RS_ZonalStatsAllBands/RS_ZonalStatsAllBands.svg" />

<Note>
  This function is more efficient than calling `RS_ZonalStatsAll` once per band. Sedona deserializes the raster only once, performs CRS conversion, intersection checks, and clipping once, and reuses the materialized raster data across all bands.
</Note>

<Note>
  If the coordinate reference system (CRS) of the input `zone` geometry differs from that of the `raster`, then `zone` is transformed to match the CRS of the `raster` before computation.

  The `raster` and `zone` geometry must intersect when `lenient` is set to `false`, otherwise an `IllegalArgumentException` is thrown. `lenient` is `true` by default, in which case the function returns `null` if the `raster` and `zone` geometry do not intersect.
</Note>

## Signatures

```sql theme={"system"}
RS_ZonalStatsAllBands(raster: Raster, zone: Geometry)
```

```sql theme={"system"}
RS_ZonalStatsAllBands(raster: Raster, zone: Geometry, allTouched: Boolean)
```

```sql theme={"system"}
RS_ZonalStatsAllBands(raster: Raster, zone: Geometry, allTouched: Boolean, excludeNodata: Boolean)
```

```sql theme={"system"}
RS_ZonalStatsAllBands(raster: Raster, zone: Geometry, allTouched: Boolean, excludeNodata: Boolean, lenient: Boolean)
```

## Parameters

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

<ParamField body="zone" type="Geometry" required>
  The zone geometry over which statistics are computed.
</ParamField>

<ParamField body="allTouched" type="Boolean">
  When `true`, include any pixel touched by the geometry; when `false` (default), include only pixels whose centroid intersects the geometry.
</ParamField>

<ParamField body="excludeNodata" type="Boolean">
  When `true` (default), exclude nodata pixels from the statistics.
</ParamField>

<ParamField body="lenient" type="Boolean">
  When `true` (default), return `null` if the raster and zone do not intersect; when `false`, throw an `IllegalArgumentException`.
</ParamField>

## Return type

<ResponseField type="Array<Struct<count, sum, mean, median, mode, stddev, variance, min, max>>">
  One struct of statistics per band, in band order.
</ResponseField>

## Example

```sql theme={"system"}
SELECT RS_ZonalStatsAllBands(raster, geom) as all_stats
FROM raster_table
```

```
[{184792.0, 1.0690406E7, 57.85, 0.0, 0.0, 92.13, 8488.45, 0.0, 255.0},
 {184792.0, 1.2345678E7, 66.82, 64.0, 0.0, 85.21, 7260.74, 0.0, 255.0},
 {184792.0, 9.876543E6, 53.39, 48.0, 0.0, 78.45, 6154.40, 0.0, 255.0}]
```

Accessing individual band statistics:

```sql theme={"system"}
SELECT
  all_stats[0].mean as band1_mean,
  all_stats[1].mean as band2_mean,
  all_stats[2].mean as band3_mean
FROM (
  SELECT RS_ZonalStatsAllBands(raster, geom) as all_stats
  FROM raster_table
)
```

```
+------------+------------+------------+
| band1_mean | band2_mean | band3_mean |
+------------+------------+------------+
|      57.85 |      66.82 |      53.39 |
+------------+------------+------------+
```
