RS_ZonalStatsAll¶
Computes every summary statistic of the raster pixels covered by a region of interest geometry and returns them as a struct.
Usage¶
struct RS_ZonalStatsAll(rast: raster, roi: geometry)
struct RS_ZonalStatsAll(rast: raster, roi: geometry, band: integer)
struct RS_ZonalStatsAll(rast: raster, roi: geometry, band: integer, all_touched: boolean)
struct RS_ZonalStatsAll(rast: raster, roi: geometry, band: integer, all_touched: boolean, exclude_no_data: boolean)
struct RS_ZonalStatsAll(rast: raster, roi: geometry, band: integer, all_touched: boolean, exclude_no_data: boolean, lenient: boolean)
Arguments¶
- rast (raster): Input raster
- roi (geometry)
- band (integer)
- all_touched (boolean)
- exclude_no_data (boolean)
- lenient (boolean): If true (the default), return NULL when the roi does not intersect the raster; if false, raise an error.
[!WARNING]
Experimental. This function is experimental; its behavior may change without notice.
Description¶
RS_ZonalStatsAll returns every summary statistic of the pixels of a
single band that a roi geometry covers, as a struct with fields count,
sum, mean, median, mode, stddev, variance, min, and max.
A pixel is included when its center falls inside the roi (or, with
all_touched, when the roi touches it at all), and the band’s nodata
pixels are excluded by default.
count is a whole number (a 64-bit integer); every other field is
floating point. Variance and standard deviation are the sample (n-1)
values, and mode breaks ties toward the larger value.
When the roi overlaps the raster but selects no pixel, count is 0 and
every other field is NULL. When the roi does not intersect the raster at
all, the whole struct is NULL under the default lenient behavior, or
the call raises an error when lenient is set to false.
The overloads are the same ladder as RS_ZonalStats without
stat_type. The band, all_touched, exclude_no_data, and lenient
arguments are added one at a time by the wider overloads; all_touched
defaults to false, exclude_no_data to true, and lenient to true. The
band-less overload does not default to band 1 on a multiband raster:
naming the band is required there. This function operates on 2-D
(y, x) bands; computing statistics per non-spatial plane of an N-D
band is not supported.
Use RS_ZonalStats to compute a single statistic.
Examples¶
SELECT RS_ZonalStatsAll(
RS_Example(),
ST_GeomFromText('POLYGON ((60 90, 160 90, 160 190, 60 190, 60 90))', 'OGC:CRS84'),
1
);
┌──────────────────────────────────────────────────────────────────────────────┐
│ rs_zonalstatsall(rs_example(),st_geomfromtext(Utf8("POLYGON ((60 90, 160 90, │
│ 160 190, 60 190, 60 90))"),Utf8("OGC:CRS84")),Int64(1))… │
╞══════════════════════════════════════════════════════════════════════════════╡
│ {count: 1542, sum: 1542.0, mean: 1.0, median: 1.0, mode: 1.0, stddev: 0.0, … │
└──────────────────────────────────────────────────────────────────────────────┘