ee.FeatureCollection.reduceColumns
Apply a reducer to each element of a collection, using the given selectors to determine the inputs.
Returns a dictionary of results, keyed with the output names.
Usage | Returns |
---|
FeatureCollection.reduceColumns(reducer, selectors, weightSelectors) | Dictionary |
Argument | Type | Details |
---|
this: collection | FeatureCollection | The collection to aggregate over. |
reducer | Reducer | The reducer to apply. |
selectors | List | A selector for each input of the reducer. |
weightSelectors | List, default: null | A selector for each weighted input of the reducer. |
Examples
// FeatureCollection of power plants in Belgium.
var fc = ee.FeatureCollection('WRI/GPPD/power_plants')
.filter('country_lg == "Belgium"');
// Calculate mean of a single FeatureCollection property.
var propMean = fc.reduceColumns({
reducer: ee.Reducer.mean(),
selectors: ['gwh_estimt']
});
print('Mean of a single property', propMean);
// Calculate mean of multiple FeatureCollection properties.
var propsMean = fc.reduceColumns({
reducer: ee.Reducer.mean().repeat(2),
selectors: ['gwh_estimt', 'capacitymw']
});
print('Mean of multiple properties', propsMean);
// Calculate weighted mean of a single FeatureCollection property. Add a fuel
// source weight property to the FeatureCollection.
var fuelWeights = ee.Dictionary({
Wind: 0.9,
Gas: 0.2,
Oil: 0.2,
Coal: 0.1,
Hydro: 0.7,
Biomass: 0.5,
Nuclear: 0.3
});
fc = fc.map(function(feature) {
return feature.set('weight', fuelWeights.getNumber(feature.get('fuel1')));
});
var weightedMean = fc.reduceColumns({
reducer: ee.Reducer.mean(),
selectors: ['gwh_estimt'],
weightSelectors: ['weight']
});
print('Weighted mean of a single property', weightedMean);
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
# FeatureCollection of power plants in Belgium.
fc = ee.FeatureCollection('WRI/GPPD/power_plants').filter(
'country_lg == "Belgium"')
# Calculate mean of a single FeatureCollection property.
prop_mean = fc.reduceColumns(**{
'reducer': ee.Reducer.mean(),
'selectors': ['gwh_estimt']
})
print('Mean of a single property:', prop_mean.getInfo())
# Calculate mean of multiple FeatureCollection properties.
props_mean = fc.reduceColumns(**{
'reducer': ee.Reducer.mean().repeat(2),
'selectors': ['gwh_estimt', 'capacitymw']
})
print('Mean of multiple properties:', props_mean.getInfo())
# Calculate weighted mean of a single FeatureCollection property. Add a fuel
# source weight property to the FeatureCollection.
def get_fuel(feature):
return feature.set('weight', fuel_weights.getNumber(feature.get('fuel1')))
fuel_weights = ee.Dictionary({
'Wind': 0.9,
'Gas': 0.2,
'Oil': 0.2,
'Coal': 0.1,
'Hydro': 0.7,
'Biomass': 0.5,
'Nuclear': 0.3
})
fc = fc.map(get_fuel)
weighted_mean = fc.reduceColumns(**{
'reducer': ee.Reducer.mean(),
'selectors': ['gwh_estimt'],
'weightSelectors': ['weight']
})
print('Weighted mean of a single property:', weighted_mean.getInfo())
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[[["`reduceColumns` applies a reducer function to properties (columns) of a FeatureCollection, effectively aggregating data across all features."],["It takes a reducer, a list of selectors specifying the properties to use as input, and optionally, weight selectors for weighted reductions."],["The output is a dictionary containing the results, keyed by the names defined within the reducer."],["This function allows for calculating statistics such as mean, sum, or other custom aggregations across the features in a FeatureCollection, using specified properties and optional weights."],["Examples provided demonstrate calculating mean and weighted mean of properties within a FeatureCollection of power plants."]]],["The `reduceColumns` function applies a reducer to a FeatureCollection, generating a dictionary of results. It uses `selectors` to specify input properties and can use `weightSelectors` for weighted inputs. The function takes a `reducer`, and a list of `selectors` and `weightSelectors`. This method can calculate means of single or multiple properties and weighted means by using a reducer and specifying properties to calculate on. The results are returned as a dictionary.\n"]]