ST_SummaryStats calculates band statistics for a raster object.
Syntax
raster ST_SummaryStats(raster raster_obj)
raster ST_SummaryStats(raster raster_obj, cstring statsOptions)
raster ST_SummaryStats(raster raster_obj, cstring bands, cstring statsOptions)Parameters
| Parameter | Description |
|---|---|
raster_obj | The raster object to analyze. |
bands | The bands to include, specified as an integer array or range. Band indexes start at 0. Examples: '0', '1-3', '1,2,3'. |
statsOptions | A JSON string specifying calculation options. See statsOptions fields below. |
statsOptions fields
| Field | Type | Default | Description |
|---|---|---|---|
approx | boolean | true | Specifies whether to use sampling to calculate statistics. |
By default,approxistrue, which uses sampling to compute statistics faster. Results may be slightly inaccurate. Setapproxtofalseto scan all pixels and get exact statistics.
Return value
Returns a raster object with statistics stored per band.
Examples
Calculate statistics for all bands using sampling (default)
UPDATE raster_obj SET raster_obj = ST_SummaryStats(raster_obj) WHERE id = 1;Calculate exact statistics for a specific band range
Pass '{"approx":false}' to scan all pixels instead of sampling. The following example calculates 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
UPDATE rast SET rast = ST_SummaryStats(rast, '{"approx":false}') WHERE id = 1;