Name

ST_CountAgg — 聚合。返回一组栅格的给定波段中的像素数。如果未指定波段,则默认为波段1。如果EXCLUDE_NODATA_VALUE设置为TRUE,将只计算不等于NODATA值的像素。

Synopsis

bigint ST_CountAgg(raster rast, integer nband, boolean exclude_nodata_value, double precision sample_percent);

bigint ST_CountAgg(raster rast, integer nband, boolean exclude_nodata_value);

bigint ST_CountAgg(raster rast, boolean exclude_nodata_value);

描述

返回一组栅格中给定波段的像素数。如果未指定波段 nband 默认为1。

如果 exclude_nodata_value 设置为True时,将只计算其值不等于 NODATA 栅格的值。集 exclude_nodata_value 设置为False,以获取所有像素的计数

默认情况下,将对所有像素进行采样。要获得更快的响应,请设置 sample_percent 设置介于零(0)和一(1)之间的值

可用性:2.2.0

示例

WITH foo AS (
    SELECT
        rast.rast
    FROM (
        SELECT ST_SetValue(
            ST_SetValue(
                ST_SetValue(
                    ST_AddBand(
                        ST_MakeEmptyRaster(10, 10, 10, 10, 2, 2, 0, 0,0)
                        , 1, '64BF', 0, 0
                    )
                    , 1, 1, 1, -10
                )
                , 1, 5, 4, 0
            )
            , 1, 5, 5, 3.14159
        ) AS rast
    ) AS rast
    FULL JOIN (
        SELECT generate_series(1, 10) AS id
    ) AS id
        ON 1 = 1
)
SELECT
    ST_CountAgg(rast, 1, TRUE)
FROM foo;

 st_countagg
-------------
          20
(1 row)
                

另请参阅

ST_Count, ST_SummaryStats, ST_SetBandNoDataValue