ST_SummaryStats
Updated at:
Copy as MD
Calculates statistics for a band set of a raster object.
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 | Description |
|---|---|
raster_obj | The raster object to analyze. |
bands | The bands to include. Accepts an integer array or an integer range. Band indexes start at 0. Examples: '0', '1-3', '1,2,3'. |
statsOptions | A JSON string specifying calculation options. See the statsOptions fields below. |
statsOptions fields
| Field | Type | Default | Description |
|---|---|---|---|
approx | Boolean | true | Specifies whether to use sampling to calculate statistics. Set to false to calculate exact statistics across all pixels. |
By default,approxistrue, which means statistics are calculated from a sample of pixels and may not be exact. To get precise results, pass'{"approx": false}'asstatsOption.
Examples
Basic usage
Calculate statistics for all bands using the default sampling method.
DO $$
DECLARE
rast raster;
BEGIN
SELECT raster_obj INTO rast FROM raster_table WHERE id = 1;
rast = ST_SummaryStats(rast);
UPDATE raster_table SET raster_obj = rast WHERE id = 1;
END;
$$ LANGUAGE 'plpgsql';Exact statistics with band selection
Calculate exact statistics (no sampling) for bands 0 through 2.
DO $$
DECLARE
rast raster;
BEGIN
SELECT raster_obj INTO rast FROM raster_table WHERE id = 1;
rast = ST_SummaryStats(rast, '0-2', '{"approx": false}');
UPDATE raster_table SET raster_obj = rast WHERE id = 1;
END;
$$ LANGUAGE 'plpgsql';Is this page helpful?