ST_CountAgg — 聚合。返回一组栅格的给定波段中像素的数量。如果没有指定波段,则默认为波段 1。如果 exclude_nodata_value 设置为 true,则只会计算不等于 NODATA 值的像素。
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)