google-earth-engine – How to Combine Feature Collections Statistics for Grouped Reductions in Google Earth Engine

google-earth-enginegoogle-earth-engine-javascript-api

There is an example in GEE Guide, about Grouped Reductions and Zonal Statistics

This code computes the total population and number of housing units for each state:

// Load a collection of US census blocks.
var blocks = ee.FeatureCollection('TIGER/2010/Blocks');

// Compute sums of the specified properties, grouped by state code.
var sums = blocks
  .filter(ee.Filter.and(
    ee.Filter.neq('pop10', null),
    ee.Filter.neq('housing10', null)))
  .reduceColumns({
    selectors: ['pop10', 'housing10', 'statefp10'],
    reducer: ee.Reducer.sum().repeat(2).group({
      groupField: 2,
      groupName: 'state-code',
    })
});

// Print the resultant Dictionary.
print(sums);

But I need, mean, min, max, and count of grouped features by states, not only summed columns of 'pop10'.

How can I achieve this? How can combine reducer for this example?

Best Answer

I found a way with combine reducers:

// Load a collection of US census blocks.
var blocks = ee.FeatureCollection('TIGER/2010/Blocks');

var reducers = ee.Reducer.mean()
                      .combine({reducer2: ee.Reducer.median(), sharedInputs: true})
                      .combine({reducer2: ee.Reducer.max(), sharedInputs: true})
                      .combine({reducer2: ee.Reducer.min(), sharedInputs: true})
                      .combine({reducer2: ee.Reducer.stdDev(), sharedInputs: true})
                      .repeat(2).group({
                            groupField: 2,
                            groupName: 'state-code',
                          })

// Compute sums of the specified properties, grouped by state code.
var sums = blocks
  .filter(ee.Filter.and(
    ee.Filter.neq('pop10', null),
    ee.Filter.neq('housing10', null)))
  .reduceColumns({
    selectors: ['pop10', 'housing10', 'statefp10'],
    reducer: reducers
});

// Print the resultant Dictionary.
print(sums);