Nom

ST_PixelAsPolygons — Retourne la géométrie polygonale qui délimite chaque pixel de la bande raster, avec la valeur et les coordonnées raster X et Y de chaque pixel.

Synopsis

setof record ST_PixelAsPolygons(raster rast, integer band=1, boolean exclude_nodata_value=TRUE);

Description

Retourne la géométrie polygonale qui délimite chaque pixel de la bande raster, avec la valeur (double précision) et les coordonnées raster X et Y (entiers) de chaque pixel.

Format de l'enregistrement de retour : geom geometry, val double precision, x entier, y entier.

[Note]

When exclude_nodata_value is TRUE, only pixels whose values are not NODATA are returned. Unlike ST_DumpAsPolygons, this function returns one polygon per pixel rather than merging adjacent pixels with the same value.

Disponibilité : 2.0.0

Amélioration : 2.1.0 ajout du paramètre optionnel exclude_nodata_value.

Changement : 2.1.1 Changement du comportement de behavior of exclude_nodata_value.

Exemples

This example returns a raster pixel polygon.

Code
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;
Export de raster
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))
Figure
Geometry figure for visual-rt-st-pixelaspolygons-01