This function is used to collect all statistics about a raster. The statistics include the histogram and percentiles.

Syntax

raster ST_ComputeStatistics(raster raster_obj, 
                            cstring sampleOption default '{}')
raster ST_ComputeStatistics(raster raster_obj, 
                            cstring bands,
                            cstring sampleOption default '{}',
                            cstring parallelOption default '{}')

Parameters

Parameter Description
raster_obj The raster that you want to query.
sampleOption A JSON string that consists of sampling options. For more information, see the "sampleOption" table in this topic.
bands The IDs of the bands. Example: '0,1-3,6,8'. Valid band IDs start from 0. If you set this parameter to '', all bands of the raster are specified.
parallelOption A JSON string that consists of parallel operation options. For more information, see the "parallelOption" table of this topic.
The following table describes the parameters in the sampleOption parameter.
Parameter Type Default value Description
approx boolean false Specifies whether to use the sampling method. Valid values: true and false.
Note If you set this parameter to true, the sampling method is used. In this case, the return result may be inaccurate.
factor integer 4 The sampling factor that is used when the sampling method is used. Valid values: any positive integer. The sampling factor specifies the number of pixels that are used as a sampling unit.
Note This parameter is valid only when you set the approx parameter to true.
exclusive_nodata boolean true Specifies whether to include NoData values. Valid values: true and false.

The following table describes the parameters in the parallelOption parameter.

Parameter Description Type Default value Remarks
parallel The degree of parallelism that is allowed. integer ganos.parallel.degree Valid values: 1 to 64.

Examples

-- Use the default parameter settings.
UPDATE raster_table SET raster_obj = ST_ComputeStatistics(raster_obj) WHERE id = 1;

-- Specify the bands and the sampling method.
UPDATE raster_table SET raster_obj = ST_ComputeStatistics(rast,'0-2','{"approx":false}') WHERE id = 1;

-- Specify the sampling method.
UPDATE raster_table SET raster_obj = ST_ComputeStatistics(rast,'{"approx":false}') WHERE id = 1;

-- Specify the bands, sampling rate, and degree of parallelism.
UPDATE raster_table SET raster_obj = ST_ComputeStatistics(raster_obj,'0-2','{"approx":true, "factor":5}', '{"parallel":4}') WHERE id = 1;