Converts pixels at a specified position of a raster into geometric objects, each represented by a point at the reference position within the geometric object.
Syntax
setof record ST_PixelAsPoints(raster raster_obj,
integer band default 0,
integer pyramid default 0,
boolean exclude_nodata_value default true,
cstring ref_point default 'UPPERLEFT',
out integer rowsn,
out integer columnsn,
out integer bandsn,
out double value,
out geometry geom);Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
raster_obj | raster | — | The raster to query. |
band | integer | 0 | The band ID to query. Valid band IDs start from 0. |
pyramid | integer | 0 | The pyramid level ID to query. |
exclude_nodata_value | boolean | true | Specifies whether to exclude NoData pixels. |
ref_point | cstring | 'UPPERLEFT' | The reference position of the point within the geometric object. Valid values: UPPERLEFT (upper-left corner) and CENTER (center). |
rowsn | out integer | — | The row number of the pixel. |
columnsn | out integer | — | The column number of the pixel. |
bandsn | out integer | — | The band ID of the pixel. |
value | out double | — | The pixel value. |
geom | out geometry | — | The spatial extent of the pixel. |
Description
ST_PixelAsPoints converts pixels at a specified position of a raster into geometric objects. Each geometric object is represented by a single point, positioned according to the ref_point parameter—either the upper-left corner (UPPERLEFT) or the center (CENTER) of the pixel geometry.
Example
The following example retrieves all pixels in band 1 from the raster with id = 10, then filters for pixels with a value greater than 38.0, returning each pixel's row, column, band, value, and geometry in Extended WKT format.
WITH tmp AS (
SELECT (ST_PixelAsPoints(rast, 1)).*
FROM rast_table
WHERE id = 10
)
SELECT rowsn, columnsn, bandsn, value, ST_AsEWKT(geom)
FROM tmp
WHERE value > 38.0;Output:
rowsn | columnsn | bandsn | value | st_asewkt
-------+----------+--------+-------+---------------------------
100 | 100 | 0 | 43 | SRID=4326;POINT(-90 0)