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)

  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'])
                  .filterDate('2016-01-01', '2016-06-30')
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))

var image = collection.sort('system:index', false).mosaic()
var image = image.clip(geom)

// Export the image, specifying scale and region.
  scale: 10,
  image: image,
  description: 'example_image',
  fileFormat: 'GeoTIFF',
  region: image.geometry().bounds().getInfo()['coordinates']

I'm assuming by "can't open it" you mean that all you're getting for an output is a black square (which is what I see when running your code). You can use the visualize() function to set visualization parameters. See the dataset's documentation for more on reflectance units. Add the following to the bottom of your code and you'll have an RGB product.

var imageRGB = image.visualize({bands: ['B4', 'B3', 'B2'], min: 0, max: 0.3});

  scale: 10,
  image: imageRGB,
  description: 'example_image_RGB',
  fileFormat: 'GeoTIFF',
  region: image.geometry().bounds().getInfo()['coordinates']
  • Hi JepsonNomad, that seemed to do the trick.Thanks a lot! – Misc584 Aug 30 '19 at 19:28

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.