1

I'm using Google Earth Engine's web-based code editor to grab a bunch of evapotranspiration snapshots, get a zonal mean, create a table of the results by date, and export to CSV. Code is below.

If I try to export using the raw date (from image.date()) for the date-data pair, I get "Error: Error: Feature: Invalid property name: **ee.Date**({" followed by a whole pile of attributes. See image below.

If I try to convert the date to a string (curDate.format('YYYYMMDD')), I get the same error, but it's "Error: Error: Feature: Invalid property name: **ee.String**({" followed by the same. See image below.

Is there a different way I should be doing this?

// Get Data
var dataset = ee.ImageCollection('MODIS/NTSG/MOD16A2/105') // ET
                  .filter(ee.Filter.date('2000-01-01', '2015-01-01'))
                  .filterBounds(AOI);
var etDataset = dataset.select('ET');
var etDatasetList = etDataset.toList(etDataset.size());
var etDatasetSize = etDatasetList.size().getInfo();

// Process
var image;
var curDate;
var curDateString;
var meanDictionary
var data = [];
for(var i = 0; i <etDatasetSize; i++){
  image = ee.Image(etDatasetList.get(i)).clip(AOI);
  curDate = image.date();
  curDateString = curDate.format('YYYYMMDD');
  meanDictionary = image.reduceRegion({
    reducer: ee.Reducer.mean(),
    geometry: AOI
  });
  data[curDate] = meanDictionary; //For if I try to use the date itself
  // data[curDateString] = meanDictionary; // For if I try to use the string
}

//Export
var feature = ee.Feature(null, data);
var featureCollection = ee.FeatureCollection([feature]);
Export.table.toDrive({
  collection: featureCollection,
  description: 'ET_Sample',
  fileFormat: 'CSV'
});

Error if I use a Date Error if I use a String

1 Answer 1

4

It is never good practice to use a for loop (client-side), especially if you want to upscale your process tot large imagecollections like you are trying here. This is an alternative .map() function (server side):

var mappedFunction = etDataset.limit(3).map(function(img){
    
  var test= etDataset.first().reduceRegion({
    reducer: ee.Reducer.mean(),
    geometry: AOI
  });
  
  // return img.set({'ET': test.get('ET')}) // append the property to the existing 
  return ee.Feature(null, test) // or if you perse want a featureCollection
  
})

print(mappedFunction, 'mappedFunction')

see additional information on the developers page: https://developers.google.com/earth-engine/guides/client_server

https://code.earthengine.google.com/1b65b50dce8bd4c87ba3c89010b35507

3
  • Thanks for responding! When I run your code using the above link unmodified and then try to export, I get the following error: "Feature, argument 'metadata': Invalid type. Expected type: Dictionary<Object>. Actual type: List<Object>. Actual value: []" Commented Feb 9, 2022 at 13:29
  • 1
    The export is still from the original function you created yourself: if the result you are looking for is indeed as I suggest then export the mappedFunction output: //Export Export.table.toDrive({ collection: mappedFunction, description: 'ET_Sample', fileFormat: 'CSV' });
    – Jobbo90
    Commented Feb 9, 2022 at 13:32
  • Whoops, sorry I missed that. That gets me where I need to go, thank you! Commented Feb 9, 2022 at 14:17

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.