1

I need to export CSV but my input is a list of lists so I have an error "FeatureCollection (Error) List.get: Parameter 'list' is required." How can I change my input data? Or the export mode?

var mod = ee.ImageCollection('MODIS/061/MOD11A1');
var point = ee.Geometry.Point(-116.0199,36.62418);
var buffer = point.buffer(564.2);
var collection = mod.filterBounds(buffer)
                    .filterDate('2022-01-01', '2023-01-01')
                    .select(['LST_Day_1km', 'Day_view_time']);
//print(collection.size());
//Map.centerObject(point, 6);
//Map.addLayer(point);
var filtered_scaled = collection.map(function(image) {
var buffer = point.buffer(564.2);
var time = image.select('Day_view_time').multiply(0.1).add(8).copyProperties(image);
var lst = image.select('LST_Day_1km').multiply(0.02).copyProperties(image, ['system:time_start', 'system:index']);
return image.addBands(time, null, true)
              .addBands(lst, null, true)
              .clip(buffer)});
              
var nImages = filtered_scaled.size();
var ImageList = filtered_scaled.toList(nImages);
var img_indices = ee.List.sequence(0,nImages.subtract(1)).getInfo();

function reduceAndPrint(index) {
  var nomScale = filtered_scaled.select('LST_Day_1km').first().projection().nominalScale();
  var nomScale2 = filtered_scaled.select('Day_view_time').first().projection().nominalScale();
  var buffer = point.buffer(564.2); // CALCULATION LST BUFFER
  var image = ee.Image(ImageList.get(index));
  
  var TmeanDay = image.select('Day_view_time').reduceRegion({
    reducer: ee.Reducer.mean(),
    maxPixels: 1e9,
    scale: nomScale2,
    geometry: buffer
  });    

  var time = TmeanDay.get('Day_view_time');
   //print(time);
    //print('time', time);
  var hours = ee.Number(time).floor().divide(1).int();
  var minutes = ee.Number(time).subtract(hours).multiply(60).round().int();
  var result = hours.format('%02d').cat(':').cat(minutes.format('%02d')).cat(':00');
      
  var systemTimeStart = ee.Date(image.get('system:time_start')).format('YYYY-MM-dd ');
  var sts = ee.String(systemTimeStart).cat(ee.String(result));
  //print('sts:', sts);
  var date = image.get('system:index');
  return ee.Algorithms.If(time, [image.id(), sts, date], null);
      } 
      
var stats = img_indices.map(reduceAndPrint); 

//print(stats);

var fc = ee.FeatureCollection(stats.map(function(list) {
    list = ee.List(list);
    var dict = {
        
        a_image_id:            list.get(0),   
        b_Day_view_time:       list.get(1),   
        c_date:                list.get(2),    
    };
  return ee.Feature(null, dict);
}));

print(fc);
// Export.table.toDrive({
//   collection: wholeYearFC,
//   description: 'DesertRock_Modis',
//   fileFormat: 'CSV',
//   folder:'ResultsFromGEE'
// });```

2 Answers 2

1

You can solve your issue by using following lines instead:

var fc = ee.FeatureCollection(stats.map(function(list) {
    list = ee.List(list);
    var dict = {
        
        a_image_id:            list.get(0),   
        b_Day_view_time:       list.get(1),   
        c_date:                list.get(2),    
    };
  
  return ee.Algorithms.If(list, ee.Feature(null, dict), null);

}));

print(fc);
Export.table.toDrive({
   collection: fc,
   description: 'DesertRock_Modis',
   fileFormat: 'CSV',
   folder:'ResultsFromGEE'
 });

After running complete code (where it was also avoided the use of getInfo), I got following CSV:

enter image description here

1
  • You should work in my university! :) After 2 weeks of trying to make my script work, finally it does! And not more 10 minutes waiting for server response. Thanx!
    – Anastasiia
    May 27, 2023 at 9:54
1

The problem is that you have some entries in your list with null; thus, when your function fc tries to get elements from that null it results in an error. An easy solution is to simply filter the List to get rid of the null entries, before getting the values and setting them as properties of a Feature. Here is the only change you need to make.

var fc = ee.FeatureCollection(
          // Filter to retain not null entries
          ee.List(stats).filter(ee.Filter.notNull(['item']))
               .map(function(list) {
                 list = ee.List(list);
                 var dict = {
                   a_image_id: list.get(0),   
                   b_Day_view_time: list.get(1),   
                   c_date: list.get(2),    
                   };
                return ee.Feature(null, dict);
               }));
1
  • I'm really grateful for your explanation coz it's important to understand the meanings of these things and how they works! Thank you.
    – Anastasiia
    May 27, 2023 at 9:57

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.