Returns the polygon geometry that bounds every pixel of a raster band, along with the pixel value and the row and column coordinates of each pixel.
Syntax
setof record ST_PixelAsPolygons(raster raster_obj,
integer band default 0,
integer pyramid default 0,
boolean exclude_nodata_value default true,
out integer rowsn,
out integer columnsn,
out integer bandsn,
out double value,
out geometry geom);Parameters
| Parameter | Description |
|---|---|
raster_obj | The raster to query. |
band | The band ID to query. Valid band IDs start from 0. Default: 0. |
pyramid | The pyramid level ID to query. Default: 0. |
exclude_nodata_value | Specifies whether to exclude NoData pixels. When true, only pixels whose values are not NoData are returned. When false, all pixels including NoData pixels are returned. Default: true. |
Return record fields
Each record in the returned set contains the following fields:
| Field | Type | Description |
|---|---|---|
rowsn | integer | The row number of the pixel. |
columnsn | integer | The column number of the pixel. |
bandsn | integer | The band ID of the pixel. |
value | double | The pixel value. |
geom | geometry | The spatial extent of the pixel as a polygon. |
Example
The following query retrieves all pixels in band 1 of the raster with id = 10, then filters for pixels with a value greater than 38.0.
WITH tmp AS (
SELECT (ST_PixelAsPolygons(rast, 1)).*
FROM rast_table
WHERE id = 10 )
SELECT rowsn, columnsn, bandsn, value, ST_AsEWKT(geom) FROM tmp WHERE value > 38.0;Output:
100 | 100 | 0 | 43 | SRID=4326;POLYGON((-180 90,-180 89.1,-179.1 89.1,-179.1 90,-180 90))