Returns the centroid (a point geometry) of the area represented by a specified raster pixel.
Syntax
geometry ST_PixelAsCentroid(raster raster_obj,
integer row default 0,
integer column default 0,
integer pyramid default 0);Parameters
| Parameter | Description |
|---|---|
raster_obj | The raster to query. |
row | The number of the row in which the pixel resides. Valid row numbers start from 0, which indicates the pixel in the upper-left corner of the raster. |
column | The number of the column in which the pixel resides. Valid column numbers start from 0, which indicates the pixel in the upper-left corner of the raster. |
pyramid | The pyramid level in which the pixel resides. |
Description
ST_PixelAsCentroid converts a specified pixel into a point geometry positioned at the centroid of the area that pixel represents. This is equivalent to calling ST_PixelAsPoint with the ref_point parameter set to CENTER.
Usage notes
Row and column indices both start from
0. The pixel at row0, column0is in the upper-left corner of the raster.The returned point is the center of the pixel area, not the upper-left corner. To return the upper-left corner point instead, use
ST_PixelAsPoint.
Example
The following query returns the centroid of the pixel at row 10, column 10 in the raster with id = 10.
SELECT ST_AsText(ST_PixelAsCentroid(rast, 10, 10))
FROM rast_table
WHERE id = 10;
------------------
POINT(-178.2 88.2)What's next
ST_PixelAsPoint: Returns a point geometry at a specified reference position of a pixel, such as the upper-left corner or center.