1

Suppose I have a featurecollection, including two aa.

How can I reduce (maybe other functions) the featurecollection by calculate the mean value of aa?

Before

 var features = [
  ee.Feature(ee.Geometry.Point(11, 22), {name: 'aa',value:10}),
  ee.Feature(ee.Geometry.Point(33, 44), {name: 'bb',value:20}),
  ee.Feature(ee.Geometry.Point(11, 22), {name: 'aa',value:30}),
  ee.Feature(ee.Geometry.Point(55, 66), {name: 'cc',value:40})
];
var fromList = ee.FeatureCollection(features);

After

var features = [
  ee.Feature(ee.Geometry.Point(11, 22), {name: 'aa',value:20}), // (10+30)/2
  ee.Feature(ee.Geometry.Point(33, 44), {name: 'bb',value:20}),
  ee.Feature(ee.Geometry.Point(55, 66), {name: 'cc',value:40})
];

1 Answer 1

2

Basically you want to itirate over the unique identifier, name in your case. and filter all features that match it, compute the mean and overwrite it. This should do the trick:

var reduce = fromList.distinct('name')

var uniqueNames = reduce.reduceColumns(ee.Reducer.toList(), ['name']).values().get(0)

var iterate = ee.List(uniqueNames).map(function(n){
  var filt = fromList.filter(ee.Filter.eq('name', n)) 
  // mean
  var mean = filt.aggregate_mean('value')
  
  // overwrite
    return ee.Feature(filt.first().set('value', mean));
  
})

https://code.earthengine.google.com/2307664929ac4485abc1c8708c5e3d6f

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.