Skip to content

RS_SummaryStats

Returns one summary statistic of a band’s pixel values as a double.

Usage

double RS_SummaryStats(rast: raster, stat_type: string)
double RS_SummaryStats(rast: raster, stat_type: string, band: integer)
double RS_SummaryStats(rast: raster, stat_type: string, band: integer, exclude_nodata: boolean)

Arguments

  • rast (raster): Input raster
  • stat_type (string): One of count, sum, mean, stddev, min or max (case-insensitive). stddev is the population standard deviation.
  • band (integer): Band index (1-based). Defaults to 1 if not specified.
  • exclude_nodata (boolean): Whether to leave pixels holding the band’s nodata value out of the statistic. Defaults to true.

Description

Over no pixels (for example, a band that is entirely nodata), count and sum are 0 and the other statistics are NaN; over one pixel, stddev is 0. A NaN pixel is left out as nodata when the band’s nodata value is NaN. Otherwise it is data: it makes sum and mean NaN, and stddev too unless it is the only pixel, while min and max skip it unless every pixel is NaN.

An unknown stat_type, a band the raster does not have, or a 64-bit integer pixel beyond 2^53 in magnitude (which a double cannot hold exactly) is an error. Only 2-D rasters are supported.

Examples

SELECT RS_SummaryStats(RS_Example(), 'mean');
┌────────────────────────────────────────────┐
│ rs_summarystats(rs_example(),Utf8("mean")) │
│                   float64                  │
╞════════════════════════════════════════════╡
│                                        1.0 │
└────────────────────────────────────────────┘
SELECT RS_SummaryStats(RS_Example(), 'count', 1, false);
┌─────────────────────────────────────────────────────────────────────┐
│ rs_summarystats(rs_example(),Utf8("count"),Int64(1),Boolean(false)) │
│                               float64                               │
╞═════════════════════════════════════════════════════════════════════╡
│                                                              2048.0 │
└─────────────────────────────────────────────────────────────────────┘