I would like to export the image from the Google Earth Engine. However, it had Error: Export region contains no valid (un-masked) pixels. How to fix this error? This is the link of my google earth engine code: https://code.earthengine.google.com/707b7d4b84a0e14f0db74b38533666e6. The code is as follow:

    // Load a Fusion Table of state boundaries and filter.
var fc = ee.FeatureCollection('ft:1tdSwUL7MVpOauSgRzqVTOwdfy17KDbw-1d9omPw')
    .filterMetadata('Country','equals','New Zealand');
// Load Landsat 8 imagery and filter it  
var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
            .filterBounds(fc).set('SENSOR_ID', 'OLI_TIRS');
var filtered = collection
  .filterMetadata('CLOUD_COVER', 'less_than', 10);
// Function to cloud mask from the Fmask band of Landsat 8 SR data.
function maskL8sr(image) {
  var cloudShadowBitMask = ee.Number(2).pow(3).int();
  var cloudsBitMask = ee.Number(2).pow(5).int();
  var qa = image.select('pixel_qa');
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
  return image.updateMask(mask).divide(10000).float();
// Map the function .
var filtered_1 = filtered.map(maskL8sr);
function a(image) {
  var equation = image.expression(
    '(7.27 * B4/B3) - 1.7',
        B3: image.select('B4'),    
        B4: image.select('B3'),   
  return image.addBands(equation);
var b = filtered_1.map(a).median();
print (b,'NEW_B');
// Display the results.
var vizParams = {bands: ['NEW_A'], min: 0, max: 100};
Map.addLayer(b, vizParams, 'recent value composite');
// Export the image, specifying scale and region.
  image: b,
  description: 'NEW_B',
  scale: 30,


All credit for this update goes for @NicholasClinton, who wisely guided me (us) to the correct answer.

The error is due to argument region for function Export.image.toDrive. It can be set when calling the function, otherwise it defaults to the viewport at the time of invocation as the documentation clearly specifies. So there are 2 solutions.

  1. Setting parameter region:
  image: b,
  description: 'NEW_B',
  scale: 30,
  region: ee.Feature(fc.first()).geometry().bounds().getInfo()['coordinates']
  1. setting the viewport at the time of exporting
Map.centerObject(fc, 9)
  image: b,
  description: 'NEW_B',
  scale: 30,

and maxPixels=1e13 because image is too big.

  • 2
    The issue is not the unboundedness. It's the fact that Export.image.toDrive() defaults to the Code Editor viewport. The ImageCollection is filtered to a bounds that is not in the same place as specified in the Map.setCenter() call. Therefore, there are no unmasked pixels in the export. One solution is to set a suitable region in the export as shown, however, the Map.setCenter() call should be replaced by Map.centerObject(fc, 9). Apr 11 '18 at 16:29
  • Thank you @NicholasClinton!! You are totally right. I updated the answer to match your comment. Apr 12 '18 at 2:50

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.