Skip to main content
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:
  • 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.
For polygon geometries, the allTouched parameter determines how pixels are selected:
  • When true, pixel selection also includes cells entered by the polygon’s boundary, following the RS_AsRaster rules.
  • When false (default), pixels whose centroid intersects the polygon will be included.
A polygon never selects a pixel it touches only on the pixel’s boundary, whichever edge that is. A polygon aligned with grid lines selects only pixels inside it. Point geometries select the single pixel containing the point under the half-open rule, regardless of allTouched. Line rasterization follows the cells entered by its segments rather than requiring a pixel-centre intersection. A point or line lying on an internal grid edge selects the pixel after it in pixel order; one lying on the raster’s last edge selects none. A neighboring pixel contacted only at a line endpoint is not selected unless the segment enters it. RS_ZonalStatsAllBands
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.
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.

Signatures

Parameters

Raster
required
The input raster.
Geometry
required
The zone geometry over which statistics are computed.
Boolean
Controls polygon pixel selection as described above; points and lines follow their geometry-specific rules.
Boolean
When true (default), exclude nodata pixels from the statistics.
Boolean
When true (default), return null if the raster and zone do not intersect; when false, throw an IllegalArgumentException.

Return type

One struct of statistics per band, in band order.

Example

Accessing individual band statistics: