0

I have two feature collections (before and after) that I want to subtract in Earth Engine. Each Feature Collection has an NDVI band computed, BF_NDVI for the before Image and AF_NDVI for the after collection.

I have written the function below from (Line 217) but it returns an error in Line 229: Object is not callable.

Any ideas on how I can solve this to get the resulting difference feature collection for export?

//Positive difference image indicates NDVI loss in the after invasion image
print('Difference_Image', difference)

//Extract before mean NDVI value
var bfMean = beforeCollectionMeans.select('BF_NDVI').first();

print('Before_Mean_NDVI', bfMean)

//Extract after mean NDVI value
var afMean = afterCollectionMeans.select('AF_NDVI').first();

print('After_Mean_NDVI', afMean)

//Get the difference mean NDVI value
var df = function(feature) {
  var diff = feature(bfMean).subtract(afMean)
  return diff;
}

var dfMean = invasionbuffer.map(df);

print('Difference_Mean_NDVI', dfMean)

The link to the full script; https://code.earthengine.google.com/ca15125c7b699144a04fd16fd76fd312

2 Answers 2

1

@Shiraz try this function I think it can help you..

var filter = ee.Filter.and(
  ee.Filter.equals({
    leftField: 'doy',
    rightField: 'doy'
  }),
  ee.Filter.equals({
    leftField: 'OBJECTID',
    rightField: 'OBJECTID'
  })
);
  
// var filter = ee.Filter.equals({leftField:'doy', rightField:'doy'})
var join = ee.Join.saveFirst('match')
var merged_all = join.apply(before_zonal_value,after_zonal_value,  filter)

// print(merged_all,"merged_all")

// Build final collection
var merged = merged_all.map(function(feat){
  var match = ee.Feature(feat.get('match'))
  var after = ee.Number(match.get('Mean_NDVI')) 
  var before = ee.Number(feat.get('Mean_NDVI'))
  var diff = before.subtract(after)
  var feture = match.set('Bef_Mean_NDVI', before)
            .set('Aft_Mean_NDVI', after)
            .set('Dif_Mean_NDVI', diff)
  var properties = feture.propertyNames()          
  var selectProperties = properties.filter(ee.Filter.neq('item', "Mean_NDVI"))
  return feture.select(selectProperties)          
})  
  

print(merged,"merged")

full code link

1

First of all, subtract method is not included in ee.Feature or ee.FeatureCollection objects. So, your function has not sense and, it is not clear what do you want to do. For instance, as BF_NDVI and AF_NDVI are the only properties of bfMean and afMean Feature Collections, I think you could set dfMean as property in invasionbuffer Feature Collection. However, modifying your script as follows (for avoiding 'Object is not callable' error):

//Positive difference image indicates NDVI loss in the after invasion image
print('Difference_Image', difference);

//Extract before mean NDVI value
var bfMean = beforeCollectionMeans.select('BF_NDVI');

print('Before_Mean_NDVI (bfMean)', bfMean);

var bfMean_list = bfMean.toList(bfMean.size());

//Extract after mean NDVI value
var afMean = afterCollectionMeans.select('AF_NDVI');

print('After_Mean_NDVI (afMean)', afMean);

var afMean_list = afMean.toList(afMean.size());

var count = invasionbuffer.size();

//Get the difference mean NDVI value
var list = ee.List.sequence(0, count.subtract(1));

var ndvi_values = list.map(function (ele) {
  
  var bf_m = ee.Feature(ee.List(bfMean_list).get(ele)).get('BF_NDVI');
  var af_m = ee.Feature(ee.List(afMean_list).get(ele)).get('AF_NDVI');
  
  var dfMean = ee.Number(bf_m).subtract(ee.Number(af_m));
  
  return [bf_m, af_m];       
});

print("ndvi_values", ndvi_values);

one of differences cannot be produced because one of list values is null; as it can be observed in red rectangle of following image.

enter image description here

Complete code is here.

1
  • thanks for modifying the script to solve the error. What I'm aiming at is getting that the difference values by subtracting the af_m from bf_m, as a feature collection for export to CSV. These are resulting values from this expression in the code; var dfMean = ee.Number(bf_m).subtract(ee.Number(af_m)) Right now the script returns a list of the bf_m & af_m values. Calculating and returning the difference of these two values is the goal. Thanks for taking the time to look into it. Much appreciated
    – Shiraz
    Commented Oct 22, 2021 at 23:32

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.