1

I created a FeatureCollection containing 63 features with a different date, from one filter per ID.

In each of these 63 features, I created a new property named "matches" that contains a new list of features, which stores a value (called LANDSAT) for each of the 50 samples I disperse in my region.

enter image description here

Now, I would like to redeem the LANDSAT value of each list item and take the average, how would I do this?

 var collection = Collection .select(["NDVI_to_ajust"], ["LANDSAT"])

      var triplets = collection.map(
        function(image) {
        return image.reduceRegions({
          collection: samplesVegPrimaCinquenta, 
          reducer: ee.Reducer.mean().setOutputs(image.bandNames()), 
          scale: 30,
        }).map(
          function(feature) {

          return feature.set({
            'imageID': image.id(),
            'date': ee.Date(image.get('system:time_start')).format('Y-MM-dd')
          })
        });
      }).flatten();
      print(triplets,'triplets') 

    var coord = function(table,rowId, colId, rowProperty, colProperty){
      var rows = table.distinct(rowProperty);
      var joined = ee.Join.saveAll('matches').apply({
        primary: rows,
        secondary: table,
        condition: ee.Filter.equals({
          leftField: rowProperty, 
          rightField: rowProperty
        })
      });
    print(joined,'join by same ID/DATE')

Here's the link code

1 Answer 1

2

if you want to add the mean to each object of the collection you can do:

var colWithMeans=joined.map(function(ft){
   ft.set('requestedMean',ee.FeatureCollection(ee.List(ft.get('matches'))).aggregate_mean('LANDSAT'));
});

And if you want the global mean (mean of means) :

var globalMean= colWithMeans.aggregate_mean('requestedMean')
5
  • Unfortionately, I got the error "FeatureCollection (Error) Error in map(ID=1_LT05_217074_19850704_00000000000000000000): AggregateFeatureCollection.mean, argument 'collection': Invalid type. Expected: FeatureCollection. Actual: List<Feature>." link Commented Jul 2, 2019 at 22:15
  • 1
    ft.set('requestedMean', ee.FeatureCollection( ee.List(ft.get('matches'))).aggregate_mean('LANDSAT')
    – Kuik
    Commented Jul 2, 2019 at 22:57
  • Thanks for help me,Kuik. I'm tryint to run this script to another different collection, but I have time out error. To continue and finalize this, can you help me? link Commented Jul 3, 2019 at 1:13
  • If you want more computation time you need to do an export, I think you don't have the choice Commented Jul 3, 2019 at 9:14
  • Thanks, Mathieu and Kuik. I've noticed that when I change the input samples of FeatureCollection, a new type of error occurs that: "FeatureCollection (Error) Parameter 'properties' is required." I dont know that it is because it is similar to the previous that I used link Commented Jul 3, 2019 at 10:23

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.