2

I have filtered a Sentinel-2 image and created a cloud mask for it based on its QA60 band. It works fine and displays with this mask applied. However, when I try to export it to a drive, I get the following error message:

Error: Image.clipToBoundsAndScale, argument 'input': Invalid type. Expected type: Image. Actual type: ImageCollection.

Why is this happening and how can I fix it? My code is below.

    //define the cloud mask layer
function maskS2clouds(image) {
  var qa = image.select('QA60');
  var cloudBitMask = 1 <<10;
  var cirrusBitMask = 1 <<11;
  
//layer called mask = the cloudy bits
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
  .and(qa.bitwiseAnd(cirrusBitMask).eq(0));
  
//'image' is a layer with the mask applied to it  
  return image.updateMask(mask).divide(10000);
}

//image collection is filtered
var dataset = ee.ImageCollection("COPERNICUS/S2")
  .filterBounds(geometry)
  .filterDate('2015-08-26', '2015-08-28')
  .map(maskS2clouds);
  
//image with mask applied
Map.addLayer(dataset);

//exported to drive
Export.image.toDrive({
    image:dataset, 
    description: '2015_CLOUDFREE',
    folder: 'users/emilywest2',
    region: geometry.geometry,
    scale: 10,
});
2

In GEE you can only export single ee.Images and not entire ImageCollections.

To get around this, you can use reducers on the ImageCollection. You can for example call .first() or .toBands() on your ImageCollection dataset. Like this:

Export.image.toDrive({
    image:dataset.toBands(), 
    description: '2015_CLOUDFREE',
    folder: 'users/emilywest2',
    region: geometry.geometry,
    scale: 10,
});
0

Because the data type of dataset is ee.ImageCollection, you can only export ee.Image.

To solve it, you can export dataset by for loop, and you need add crs parameter. Like this:

dataset=dataset.toList(dataset.size());
for(var i=0; i<dataset.size().getInfo(); i++){   
    Export.image.toDrive({
        image:ee.Image(dataset.get(i)), 
        description: '2015_CLOUDFREE_'+i,
        folder: 'users/emilywest2',
        region: geometry.geometry,
        scale: 10,
        crs:'EPSG:4326'
    });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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