ST_SummaryStatsAgg
Prev | 12.9. Raster Band Statistics and Analytics | Next

## Name

ST_SummaryStatsAgg — Aggregate. Returns summarystats consisting of count, sum, mean, stddev, min, max for a given raster band of a set of raster. Band 1 is assumed is no band is specified.

## Synopsis

`summarystats ST_SummaryStatsAgg(`setof raster rast, integer nband, boolean exclude_nodata_value, double precision sample_percent`)`;

`summarystats ST_SummaryStatsAgg(`setof raster rast, boolean exclude_nodata_value, double precision sample_percent`)`;

`summarystats ST_SummaryStatsAgg(`setof raster rast, integer nband, boolean exclude_nodata_value`)`;

## Description

Returns summarystats consisting of count, sum, mean, stddev, min, max for a given raster band of a raster or raster coverage. If no band is specified `nband` defaults to 1.

By default only considers pixel values not equal to the `NODATA` value. Set `exclude_nodata_value` to False to get count of all pixels.

By default will sample all pixels. To get faster response, set `sample_percent` to value between 0 and 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
        (stats).count,
        round((stats).sum::numeric, 3),
        round((stats).mean::numeric, 3),
        round((stats).stddev::numeric, 3),
        round((stats).min::numeric, 3),
        round((stats).max::numeric, 3)
    FROM (
        SELECT
            ST_SummaryStatsAgg(rast, 1, TRUE, 1) AS stats
        FROM foo
    ) bar;

     count |  round  | round  | round |  round  | round
    -------+---------+--------+-------+---------+-------
        20 | -68.584 | -3.429 | 6.571 | -10.000 | 3.142
    (1 row)

## See Also

summarystats, ST_SummaryStats, ST_Count, ST_Clip

Prev | Up | Next
ST_SummaryStats | Home | ST_ValueCount