All Products
Search
Document Center

PolarDB:ST_PixelAsPolygons

Last Updated:Mar 28, 2026

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

ParameterDescription
raster_objThe raster to query.
bandThe band ID to query. Valid band IDs start from 0. Default: 0.
pyramidThe pyramid level ID to query. Default: 0.
exclude_nodata_valueSpecifies 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:

FieldTypeDescription
rowsnintegerThe row number of the pixel.
columnsnintegerThe column number of the pixel.
bandsnintegerThe band ID of the pixel.
valuedoubleThe pixel value.
geomgeometryThe 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))