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

Returns a struct of statistic values, where each statistic is computed over a region defined by the `zone` geometry. The struct has the following schema:

The `allTouched` parameter (Since `v1.7.1`) determines how pixels are selected:

* When true, any pixel touched by the geometry will be included.
* When false (default), only pixels whose centroid intersects with the geometry will be included.

<img src="https://mintcdn.com/wherobots/AayJA2u8CknIeTgt/images/sql-functions/RS_ZonalStatsAll_allTouched/RS_ZonalStatsAll_allTouched.svg?fit=max&auto=format&n=AayJA2u8CknIeTgt&q=85&s=7005d4caef39263212e5d6712734b0b9" alt="RS_ZonalStatsAll_allTouched" width="820" height="410" data-path="images/sql-functions/RS_ZonalStatsAll_allTouched/RS_ZonalStatsAll_allTouched.svg" />

* 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.

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

  The following conditions will throw an `IllegalArgumentException` if they are not met:

  * The provided `raster` and `zone` geometry should intersect when `lenient` parameter is set to `false`.
  * The option provided to `statType` should be valid.

  `lenient` parameter is set to `true` by default. The function will return `null` if the `raster` and `zone` geometry do not intersect.
</Note>

<img src="https://mintcdn.com/wherobots/AayJA2u8CknIeTgt/images/sql-functions/RS_ZonalStatsAll/RS_ZonalStatsAll.svg?fit=max&auto=format&n=AayJA2u8CknIeTgt&q=85&s=b4e588aeba6341f6bf96d108254af112" alt="RS_ZonalStatsAll" width="750" height="420" data-path="images/sql-functions/RS_ZonalStatsAll/RS_ZonalStatsAll.svg" />

## Signatures

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

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

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

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

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

## Parameters

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

<ParamField body="zone" type="Geometry" required>
  The zone value.
</ParamField>

<ParamField body="band" type="Integer">
  The band index.
</ParamField>

<ParamField body="allTouched" type="Boolean">
  The all touched value.
</ParamField>

<ParamField body="excludeNodata" type="Boolean">
  The exclude nodata value.
</ParamField>

<ParamField body="lenient" type="Boolean">
  The lenient value.
</ParamField>

## Return type

<ResponseField type="Struct<count: Long, sum: Double, mean: Double, median: Double, mode: Double, stddev: Double, variance: Double, min: Double, max: Double>">
  A struct containing the result fields.
</ResponseField>

## Examples

```sql theme={"system"}
RS_ZonalStatsAll(rast1, geom1, 1, true, false)
```

```
{184792.0, 1.0690406E7, 57.851021689230684, 0.0, 0.0, 92.13277429243035, 8488.448098819916, 0.0, 255.0}
```

```sql theme={"system"}
RS_ZonalStatsAll(rast2, geom2, 1, false, true)
```

```
{14184.0, 3213526.0, 226.55992667794473, 255.0, 255.0, 74.87605357255357, 5606.423398599913, 1.0, 255.0}
```
