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
| Parameter | Description |
|---|---|
raster_obj | The raster to query. |
band | The band to query. Valid band IDs start from 0. Default value: 0. |
pyramid | The pyramid level to query. Default value: 0. |
exclude_nodata_value | Specifies whether to exclude nodata pixels. Default value: true. |
rowsn | The row number of the pixel. |
columnsn | The column number of the pixel. |
bandsn | The ID of the band to which the pixel belongs. |
value | The pixel value, as a double precision floating-point number. |
geom | The 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)