1

I am working on cloud masking, on a collection of Modis images in google earth engine.The code below works for the cloud masking part however when i try exporting the collection it returns an error as below Error: Image.clipToBoundsAndScale, argument 'input': Invalid type. Expected: Image. Actual: ImageCollection.
error returned I don't know where the problem is that is causing the error

var maskEmptyPixels = function(image) {
  var withObs = image.select('EVI').gt(0);
  return image.updateMask(withObs); 
  };
var maskClouds = function(image) {
  var QA = image.select('SummaryQA');
  var bitMask = 1 << 10;
  return image.updateMask(QA.bitwiseAnd(bitMask).eq(0));
}; 
var table_bounds = function(image){
 return image.clip(table); 
};
var collection =ee.ImageCollection('MODIS/006/MOD13Q1' )
               .filterDate('2019-03-01', '2019-07-30')
                .filterBounds(table).select('EVI','SummaryQA')
                .map(maskEmptyPixels);
var evicollection = collection.map(table_bounds);
var totalObsCount = evicollection
        .select('EVI')
        .count();
var collectionCloudMasked = evicollection.map(maskClouds);
var clearObsCount = collectionCloudMasked
        .select('EVI')
        .count()
        .unmask(0);
Map.setCenter(35.94,-0.37,8);
Map.addLayer(
    collectionCloudMasked.median(),
    {bands: ['EVI'],
     gain: 0.07,
     gamma: 1.4
    },
    'median of masked collection'
  );
  print(collectionCloudMasked);
var list = collectionCloudMasked.toList(11);
for(var i=1;i<11;i++){
  var nam=ee.String('EVI_img')
             .cat(ee.String(ee.Number(i)))
             .getInfo();
}
Export.image.toDrive({   
       image: collectionCloudMasked,
       description: nam,
       scale:250,
       maxPixels:1e13
});

1 Answer 1

1

You can only export a single image using the Export.toDrive(). Make sure the for loop you provide return a name and a corresponding image, and then export it within the loop. Note also that GEE list start index is zero.

var list = collectionCloudMasked.toList(11);
for(var i=0;i<11;i++){
  // make a client-side name for export
  var nam = ee.String('EVI_img')
             .cat(ee.String(ee.Number(i)))
             .getInfo();

  // get the image from the collection.toList()
  var imgExport = ee.Image(list.get(i))

  Export.image.toDrive({   
         image: imgExport,
         description: nam,
         scale:250,
         maxPixels:1e13
  });
}

link code

3
  • 2
    It is because this line var imgExport = ee.Image(list.get[i]) is wrong. It should be var imgExport = ee.Image(list.get(i)).
    – xunilk
    Apr 2, 2020 at 20:44
  • Thanks ,,,it worked.
    – Patricia
    Apr 3, 2020 at 16:08
  • @Patricia If it worked, you should mark the answer as accepted.
    – xunilk
    Apr 5, 2020 at 3:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.