RS_ZonalStatsAll¶
Introduction: 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:
For polygon geometries, the allTouched parameter (Since v1.7.1) 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. 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. When allTouched is false, a line selects the pixels GDAL selects by default: each segment selects the pixels that contain its two ends and one pixel in every pixel column between them, or in every pixel row when the ends are more rows apart than columns. That is fewer pixels than the segment passes through, it can include a pixel the segment does not pass through, and a line and its reverse can select different pixels. When allTouched is true, a line selects the pixels GDAL selects with ALL_TOUCHED: every pixel a segment passes through, and a pixel it meets only at a single point when that point belongs to the pixel under the half-open rule. Both rules are described for RS_AsRaster. Whether a coordinate lies on a grid line is decided in decimal, as described for RS_AsRaster.
- 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
rasterandzonegeometry should intersect whenlenientparameter is set tofalse. - The option provided to
statTypeshould be valid.
lenient parameter is set to true by default. The function will return null if the raster and zone geometry do not intersect.
Format:
RS_ZonalStatsAll(raster: Raster, zone: Geometry)
RS_ZonalStatsAll(raster: Raster, zone: Geometry, band: Integer)
RS_ZonalStatsAll(raster: Raster, zone: Geometry, band: Integer, allTouched: Boolean)
RS_ZonalStatsAll(raster: Raster, zone: Geometry, band: Integer, allTouched: Boolean, excludeNodata: Boolean)
RS_ZonalStatsAll(raster: Raster, zone: Geometry, band: Integer, allTouched: Boolean, excludeNodata: Boolean, lenient: Boolean)
Return type: Struct<count: Long, sum: Double, mean: Double, median: Double, mode: Double, stddev: Double, variance: Double, min: Double, max: Double>
Since: v1.5.1
SQL Example
RS_ZonalStatsAll(rast1, geom1, 1, true, false)
Output:
{184792.0, 1.0690406E7, 57.851021689230684, 0.0, 0.0, 92.13277429243035, 8488.448098819916, 0.0, 255.0}
SQL Example
RS_ZonalStatsAll(rast2, geom2, 1, false, true)
Output:
{14184.0, 3213526.0, 226.55992667794473, 255.0, 255.0, 74.87605357255357, 5606.423398599913, 1.0, 255.0}