[GIS] Error in export image from Google Earth Engine

google-earth-engine

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)
      .and(qa.bitwiseAnd(cloudsBitMask).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'),   
    }).rename('NEW_A').float();
  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.
Export.image.toDrive({
  image: b,
  description: 'NEW_B',
  scale: 30,
});

Best Answer

UPDATE

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:
Export.image.toDrive({
  image: b,
  description: 'NEW_B',
  scale: 30,
  maxPixels:1e13,
  region: ee.Feature(fc.first()).geometry().bounds().getInfo()['coordinates']
});
  1. setting the viewport at the time of exporting
Map.centerObject(fc, 9)
Export.image.toDrive({
  image: b,
  description: 'NEW_B',
  scale: 30,
  maxPixels:1e13
});

and maxPixels=1e13 because image is too big.

Related Question