Queries the pixel values at specified quantiles for a raster object.
Run ST_StatsQuantile on the raster object before calling ST_Quantile. ST_Quantile reads pre-computed statistics rather than recalculating them.
Syntax
setof record ST_Quantile(raster raster_obj,
float8[] quantiles default NULL,
cstring bands default '',
boolean exclude_nodata_value default true,
out integer band,
out float8 quantile,
out float8 value)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
raster_obj | raster | — | The raster object to query. |
quantiles | float8[] | NULL | The quantiles to compute. Valid values: 0.25, 0.5, and 0.75. Specify one or more values as an array. If NULL, all three quantiles (0.25, 0.5, 0.75) are returned. |
bands | cstring | '' | The bands to include. Use '0-2' for a range or '1,2,3' for individual bands. Band serial numbers start from 0. An empty string selects all bands. |
exclude_nodata_value | boolean | true | Specifies whether to exclude NoData pixels from the calculation. |
band (out) | integer | — | The band serial number. |
quantile (out) | float8 | — | The quantile value. |
value (out) | float8 | — | The pixel value at that quantile. |
Examples
All examples use the rat_quantile table and expand the setof record result with .*.
Query the 0.25 quantile pixel value across all bands.
SELECT (ST_Quantile(rast, ARRAY[0.25], '0-2', true)).* FROM rat_quantile WHERE id = 1; band | quantile | value
------+----------+-------
0 | 0.25 | 11
1 | 0.25 | 10
2 | 0.25 | 50
(3 rows)Query pixel values at the 0.25, 0.5, and 0.75 quantiles for band 0.
Passing NULL for the quantiles parameter returns all three common quantiles.
SELECT (ST_Quantile(rast, NULL, '0', true)).* FROM rat_quantile WHERE id = 1; band | quantile | value
------+----------+-------
0 | 0.25 | 11
0 | 0.5 | 11
0 | 0.75 | 65
(3 rows)