0

I am trying to pass many annual images through the following function to find the mean image value in each feature:

var means = function(image){
  var out = fun(image)
  out = out.reduceRegions({
  collection: geometry,
  reducer: ee.Reducer.mean(),
  scale: 30,
  })
  out = out.map(function(feat){
  return ee.Feature(feat.geometry(), { 
    NAME: feat.get('mean'),
    fid: feat.get(id)
   })
  })
  return out
}

var meansout = [];
for (var i = startyear; i <= endyear; i++) {
  meansout[i] = means(i)
}

However, since I'm doing it on a lot of images, I need the property 'NAME' to include the iteration (e.g., 'NAME_2010') or another unique identifier so I can later merge the feature collections.

Here's an example with the code above: https://code.earthengine.google.com/16d351ea852cd5394a3a16c00ac12129

I have tried using something like out.select(['NAME'], ['NAME_'+i]), but this doesn't work for features where there is missing data to aggregate. I also looked at this question/answer, but the feature properties within ee.Feature(feat.geometry(), { }) isn't allowing me to use i+ in the same way.

1 Answers1

0

I believe the best tool for this case is dictionary, where you use year as the key and data you want to collect as the value. Create it before the loop:

var NAME = {};

And later in the loop for the year i

NAME[i] = feat.get('mean');
Daria T
  • 31
  • 4