Returns the pixel value at a given percentile for a specified band of a raster — for example, the value below which 25%, 50%, or 75% of pixels fall. Use this function to analyze pixel intensity or elevation distributions in raster data.
Syntax
float8 ST_Percentile(raster raster_obj, integer band, integer percentage)Parameters
| Parameter | Type | Description |
|---|---|---|
raster_obj | raster | The raster to query. |
band | integer | The band ID. Valid IDs start from 0. |
percentage | integer | The target percentile. The raster must have precomputed percentile statistics before you call this function. To precompute statistics, call ST_BuildPercentiles or ST_ComputeStatistics. |
Examples
The following examples query the 10th, 25th, and 50th percentiles for band 0 of a raster row.
Query a single percentile
SELECT st_percentile(rast_obj, 0, 10)
FROM raster_table
WHERE id = 1;Result:
29.7Query multiple percentiles
ST_Percentile produces the same result as ST_Quantile. The following example retrieves the 25th and 50th percentiles in a single query.
SELECT st_percentile(rast_obj, 0, 25), st_percentile(rast_obj, 0, 50)
FROM raster_table
WHERE id = 1;