I am trying to export a clipped satellite image from Google Earth Engine's Code Editor. I am able to see the image correctly within code editor, but am unable to open the exported image in Google Drive or on my computer if I download it.
My code is below, does anyone know what the problem might be?
/**
* Function to mask clouds using the Sentinel-2 QA band
* @param {ee.Image} image Sentinel-2 image
* @return {ee.Image} cloud masked Sentinel-2 image
*/
function maskS2clouds(image) {
var qa = image.select('QA60');
// Bits 10 and 11 are clouds and cirrus, respectively.
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask).divide(10000);
}
var geom = ee.Geometry.Polygon([[33.8777, -13.4055],
[33.8777, -13.3157],
[33.9701, -13.3157],
[33.9701, -13.4055]])
var collection = (ee.ImageCollection("COPERNICUS/S2")
.select(['B4', 'B3', 'B2', 'QA60'])
.filterBounds(geom)
.filterDate('2016-01-01', '2016-06-30')
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
.map(maskS2clouds)
)
var image = collection.sort('system:index', false).mosaic()
var image = image.clip(geom)
// Export the image, specifying scale and region.
Export.image.toDrive({
scale: 10,
image: image,
description: 'example_image',
fileFormat: 'GeoTIFF',
region: image.geometry().bounds().getInfo()['coordinates']
});