Announcement: All noncommercial projects registered to use Earth Engine beforeApril 15, 2025 mustverify noncommercial eligibility to maintain access. If you have not verified by September 26, 2025, your access may be on hold.

ee.FeatureCollection.reduceColumns

  • FeatureCollection.reduceColumns applies a reducer to each element of a collection using specified selectors for input.

  • The method returns a dictionary of results, with keys corresponding to the output names.

  • The usage involves specifying a reducer, input selectors, and optionally weight selectors.

  • Arguments include the collection itself, the reducer, a list of selectors for inputs, and an optional list of weight selectors.

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.

UsageReturns
FeatureCollection.reduceColumns(reducer, selectors,weightSelectors)Dictionary
ArgumentTypeDetails
this:collectionFeatureCollectionThe collection to aggregate over.
reducerReducerThe reducer to apply.
selectorsListA selector for each input of the reducer.
weightSelectorsList, default: nullA selector for each weighted input of the reducer.

Examples

Code Editor (JavaScript)

// FeatureCollection of power plants in Belgium.varfc=ee.FeatureCollection('WRI/GPPD/power_plants').filter('country_lg == "Belgium"');// Calculate mean of a single FeatureCollection property.varpropMean=fc.reduceColumns({reducer:ee.Reducer.mean(),selectors:['gwh_estimt']});print('Mean of a single property',propMean);// Calculate mean of multiple FeatureCollection properties.varpropsMean=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.varfuelWeights=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){returnfeature.set('weight',fuelWeights.getNumber(feature.get('fuel1')));});varweightedMean=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 usinggeemap for interactive development.

importeeimportgeemap.coreasgeemap

Colab (Python)

# 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']})display('Mean of a single property:',prop_mean)# Calculate mean of multiple FeatureCollection properties.props_mean=fc.reduceColumns(**{'reducer':ee.Reducer.mean().repeat(2),'selectors':['gwh_estimt','capacitymw']})display('Mean of multiple properties:',props_mean)# Calculate weighted mean of a single FeatureCollection property. Add a fuel# source weight property to the FeatureCollection.defget_fuel(feature):returnfeature.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']})display('Weighted mean of a single property:',weighted_mean)

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2023-10-06 UTC.