ST_CountAgg
Name
ST_CountAgg — Aggregate. Returns the number of pixels in a given band of a set of rasters. If no band is specified defaults to band 1. If exclude_nodata_value is set to true, will only count pixels that are not equal to the NODATA value.
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
)
;
Description
Returns the number of pixels in a given band of a set of rasters. If no band is specified
nband
defaults to 1.
If
exclude_nodata_value
is set to true, will only count pixels with value not equal to the
NODATA
value of the raster. Set
exclude_nodata_value
to false to get count all pixels
By default will sample all pixels. To get faster response, set
sample_percent
to value between zero (0) and one (1)
Availability: 2.2.0
Examples
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)