1

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?

1 Answer 1

1

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.