Calculates statistics for a specified set of bands in a raster object and writes the results back to the raster.
Syntax
raster ST_SummaryStats(raster raster_obj)
raster ST_SummaryStats(raster raster_obj, cstring statsOption)
raster ST_SummaryStats(raster raster_obj, cstring bands, cstring statsOption)Parameters
| Parameter | Type | Description |
|---|---|---|
raster_obj | raster | The raster object to compute statistics for. |
bands | cstring | The bands to compute statistics for. Accepts an integer array or an integer range. Band sequence numbers start at 0. Examples: '0', '1-3', '1,2,3'. |
statsOptions | cstring | A JSON string that specifies the statistics options. See statsOptions. |
statsOptions
| Parameter | Type | Default | Description |
|---|---|---|---|
approx | boolean | true | Specifies whether to use sampling to estimate statistics. true: use sampling (faster, but results may be approximate). false: compute exact statistics across all pixels. |
By default,approxistrue. Set"approx": falsefor exact results. Sampling is faster on large rasters but the statistics may differ slightly from exact values.
Examples
All examples use an UPDATE statement to write the computed statistics back to the raster object.
Calculate statistics for all bands using default options (sampling enabled):
UPDATE raster_obj SET raster_obj=ST_SummaryStats(raster_obj) WHERE id = 1;Calculate exact statistics for bands 0 through 2:
UPDATE rast SET rast=ST_SummaryStats(rast,'0-2','{"approx":false}') WHERE id = 1;Calculate exact statistics for all bands without specifying a band range:
UPDATE rast SET rast=ST_SummaryStats(rast,'{"approx":false}') WHERE id = 1;