All Products
Search
Document Center

PolarDB:ST_PixelAsCentroids

Last Updated:Mar 28, 2026

Converts raster pixels to geometric objects, each represented by the centroid of the pixel's spatial extent.

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 precision value,
    out geometry geom);

Description

ST_PixelAsCentroids returns one record per pixel, where the geometry (geom) is the center point of the pixel's spatial extent. This is equivalent to calling ST_PixelAsPoints with ref_point set to CENTER.

Parameters

ParameterDescription
raster_objThe raster to query.
bandThe band to query. Valid band IDs start from 0. Default value: 0.
pyramidThe pyramid level to query. Default value: 0.
exclude_nodata_valueSpecifies whether to exclude nodata pixels. Default value: true.
rowsnThe row number of the pixel.
columnsnThe column number of the pixel.
bandsnThe ID of the band to which the pixel belongs.
valueThe pixel value, as a double precision floating-point number.
geomThe centroid of the pixel's spatial extent, as a geometry object.

Examples

The following example queries pixels from band 1 of the raster with id = 10 in rast_table, and returns only those with a pixel value greater than 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;

----------------------------------------------------
    100 |      100 |      0 |    43 | SRID=4326;POINT(-89.5 0.5)