名称

ST_PixelAsPolygons — 返回包围栅格带的每个像素的多边形几何图形以及每个像素的值、X 和 Y 栅格坐标。

大纲

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

Description

返回包围栅格带的每个像素的多边形几何图形以及每个像素的值(双精度)、X 和 Y 栅格坐标(整数)。

返回记录格式:geom geometryval双精度,x整数,y整数。

[注意]

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.

可用性: 2.0.0

增强:2.1.0 添加了 except_nodata_value 可选参数。

更改:2.1.1 更改了 except_nodata_value 的行为。

示例

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;
栅格输出
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