All Products
Search
Document Center

PolarDB:ST_PixelAsCentroids

Last Updated:Mar 28, 2026

Returns the centroid of each pixel in a raster as a point geometry, along with the pixel's row, column, band, and value.

Syntax

setof record ST_PixelAsCentroids(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 to query. Valid IDs start from 0.
pyramidThe pyramid level to query.
exclude_nodata_valueSpecifies whether to exclude NoData pixels. Default: true.
rowsn(Out) Row number of the pixel.
columnsn(Out) Column number of the pixel.
bandsn(Out) Band ID of the pixel.
value(Out) Pixel value.
geom(Out) Center point of the pixel, returned as a point geometry.

Description

Each record returned contains (rowsn, columnsn, bandsn, value, geom), where geom is a point geometry at the center of the pixel.

When exclude_nodata_value is true, pixels with NoData values are excluded from the results. If your query returns fewer rows than expected, check whether NoData pixels are being filtered out.

This function produces the same results as ST_PixelAsPoints when ref_point is set to CENTER.

Example

The following query retrieves pixels from band 1 of the raster with id = 10, then filters to pixels with values above 38.0.

WITH tmp AS (
SELECT (ST_PixelAsCentroids(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;POINT(-89.5 0.5)

See also

  • ST_PixelAsPoints: Returns pixel geometries using a configurable reference point (set ref_point to CENTER for equivalent results).