Nome

ST_Polygon — Retorna um multipolígono formado pela união de pixeis que têm um valor que não é um valor sem dados. Se um número de banda for especificado, usa-se 1.

Sinopse

geometry ST_Polygon(raster rast, integer band_num=1);

Description

Changed 3.3.0, validation and fixing is disabled to improve performance. May result invalid geometries.

Disponibilidade: 0.1.6 Requer GDAL 1.7 ou superior.

Melhorias: 2.1.0 Velocidade aprimorada (fully C-Based) e o multipolígono que retorna é assegurado como válido.

Alterações: 2.1.0 Nas versões anteriores retornaria polígono, foi alterado para sempre voltar multipolígono.

Exemplos

Compare polygonization of every pixel with polygonization after zero is assigned as the NODATA value. The latter preserves the gap formed by zero-valued cells.

Code
WITH source AS (
    SELECT ST_SetValues(
        ST_AddBand(
            ST_MakeEmptyRaster(4, 4, 0, 4, 1, -1, 0, 0, 0),
            1, '8BUI', 1, NULL
        ),
        1, 1, 1,
        ARRAY[
            [1, 1, 1, 1],
            [1, 0, 0, 1],
            [1, 1, 0, 1],
            [1, 1, 1, 1]
        ]::double precision[][]
    ) AS rast
), variants AS (
    SELECT 'all pixels' AS title, ST_Polygon(rast) AS geom
    FROM source
    UNION ALL
    SELECT
        'zero excluded',
        ST_Polygon(ST_SetBandNoDataValue(rast, 1, 0))
    FROM source
)
SELECT title, geom AS geom
FROM variants
ORDER BY CASE title
    WHEN 'all pixels' THEN 1
    ELSE 2
END;
Raster Outputs
title         | geom
---------------+----------------------------------------------------------------------
 all pixels    | MULTIPOLYGON(((0 4,4 4,4 0,0 0,0 4)))
 zero excluded | MULTIPOLYGON(((0 4,0 0,4 0,4 4,0 4),(1 3,3 3,3 1,2 1,2 2,1 2,1 3)))
(2 rows)
Figure
Geometry figure for visual-rt-st-polygon-01

Veja também

ST_Value, ST_DumpAsPolygons