All Products
Search
Document Center

ApsaraDB RDS: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 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

ParameterDescription
raster_objThe raster to query.
bandThe band ID to query. Band IDs start from 0. Default: 0.
pyramidThe pyramid level ID to query. Default: 0.
exclude_nodata_valueSpecifies whether to exclude NoData pixels from the result set. Default: true.

Output columns

Each row returned by the function contains the following columns:

ColumnTypeDescription
rowsnintegerThe row number of the pixel.
columnsnintegerThe column number of the pixel.
bandsnintegerThe band ID the pixel belongs to.
valuedoubleThe pixel value.
geomgeometryThe 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 geometries

  • ST_PixelAsPolygon — returns the polygon geometry for a single pixel at a specified row and column

  • ST_PixelAsPoint — returns the point geometry for a single pixel

  • ST_PixelAsPoints — returns point geometries for all pixels in a band

  • ST_PixelAsCentroid — returns the centroid of the polygon for a single pixel

  • ST_PixelAsCentroids — returns the centroid geometries for all pixels in a band