ST_PixelAsPolygons — Returns the polygon geometry that bounds every pixel of a raster band along with the value, the X and the Y raster coordinates of each pixel.
setof record ST_PixelAsPolygons(raster rast, integer band=1, boolean exclude_nodata_value=TRUE);
Returns the polygon geometry that bounds every pixel of a raster band along with the value (double precision), the X and the Y raster coordinates (integers) of each pixel.
Return record format: geom geometry, val double precision, x integer, y integers.
|
|
|
When |
Availability: 2.0.0
Enhanced: 2.1.0 exclude_nodata_value optional argument was added.
Changed: 2.1.1 Changed behavior of exclude_nodata_value.
This example returns a raster pixel polygon.
WITH raster AS (
SELECT ST_SetValue(
ST_SetValue(
ST_AddBand(
ST_MakeEmptyRaster(
2, 2, 0, 0, 0.001, -0.001, 0.001, 0.001, 4269
),
1, '8BUI', 1, 0
),
2, 2, 10
),
1, 1, NULL
) AS rast
), pixels AS (
SELECT (ST_PixelAsPolygons(rast)).*
FROM raster
)
SELECT x, y, val, geom AS geom
FROM pixels
ORDER BY x, y;
x | y | val | geom ---+---+----------------------------------------------------------------------------- 1 | 2 | 1 | POLYGON((0.001 -0.001,0.002 0,0.003 -0.001,0.002 -0.002,0.001 -0.001)) 2 | 1 | 1 | POLYGON((0.001 0.001,0.002 0.002,0.003 0.001,0.002 0,0.001 0.001)) 2 | 2 | 10 | POLYGON((0.002 0,0.003 0.001,0.004 0,0.003 -0.001,0.002 0))