Returns the polygon geometry that bounds every pixel of a raster band, along with the pixel value and its row and column coordinates.
Unlike ST_DumpAsPolygons, which groups pixels with the same value into a single geometry, ST_PixelAsPolygons returns one polygon per 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. 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 from the result set. Default: true. |
Output columns
Each row returned by the function contains the following columns:
| Column | Type | Description |
|---|---|---|
rowsn | integer | The row number of the pixel. |
columnsn | integer | The column number of the pixel. |
bandsn | integer | The band ID the pixel belongs to. |
value | double | The pixel value. |
geom | geometry | The spatial extent (polygon) of the pixel. |
Example
The following example queries rast_table for pixels in band 1, then filters the result to rows where the pixel value exceeds 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;Example output:
rowsn | columnsn | bandsn | value | st_asewkt
-------+----------+--------+-------+------------------------------------------------------------
100 | 100 | 0 | 43 | SRID=4326;POLYGON((-180 90,-180 89.1,-179.1 89.1,-179.1 90,-180 90))See also
ST_DumpAsPolygons— groups pixels with the same value into merged polygon geometriesST_PixelAsPolygon— returns the polygon geometry for a single pixel at a specified row and columnST_PixelAsPoint— returns the point geometry for a single pixelST_PixelAsPoints— returns point geometries for all pixels in a bandST_PixelAsCentroid— returns the centroid of the polygon for a single pixelST_PixelAsCentroids— returns the centroid geometries for all pixels in a band