imageexportsizegoogle-earth-engine

How can I export this very large image in Google Earth Engine?


It is giving me an error when trying to submit the task : "Request payload size exceeds the limit: 10485760 bytes."

What can I change to be able to make it exportable, and relatively quickly. Also just to double check, am I exporting the right image file? I chose image "NDVI". Also, can I include the legend in the downloaded image?

var s2 = ee.ImageCollection("COPERNICUS/S2");
var admin2 = ee.FeatureCollection("FAO/GAUL_SIMPLIFIED_500m/2015/level2");

var bangalore = admin2.filter(ee.Filter.eq('ADM0_NAME', 'Afghanistan'))
var geometry = bangalore.geometry()

var filtered = s2.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
  .filter(ee.Filter.date('2019-01-01', '2019-12-31'))
  .filter(ee.Filter.bounds(geometry))

var image = filtered.median(); 

// Calculate  Normalized Difference Vegetation Index (NDVI)
// 'NIR' (B8) and 'RED' (B4)
var ndvi = image.normalizedDifference(['B8', 'B4']).rename(['ndvi']);

var palette = ['#d7191c','#fdae61','#ffffbf','#a6d96a','#1a9641']
var ndviVis = {min:0, max:0.5, palette: palette}
Map.centerObject(geometry)
Map.addLayer(ndvi.clip(geometry), ndviVis, 'ndvi')


function createColorBar(titleText, palette, min, max) {
  // Legend Title
  var title = ui.Label({
    value: titleText, 
    style: {fontWeight: 'bold', textAlign: 'center', stretch: 'horizontal'}});

  // Colorbar
  var legend = ui.Thumbnail({
    image: ee.Image.pixelLonLat().select(0),
    params: {
      bbox: [0, 0, 1, 0.1],
      dimensions: '200x20',
      format: 'png', 
      min: 0, max: 1,
      palette: palette},
    style: {stretch: 'horizontal', margin: '8px 8px', maxHeight: '40px'},
  });
  
  // Legend Labels
  var labels = ui.Panel({
    widgets: [
      ui.Label(min, {margin: '4px 10px',textAlign: 'left', stretch: 'horizontal'}),
      ui.Label((min+max)/2, {margin: '4px 20px', textAlign: 'center', stretch: 'horizontal'}),
      ui.Label(max, {margin: '4px 10px',textAlign: 'right', stretch: 'horizontal'})],
    layout: ui.Panel.Layout.flow('horizontal')});
  
  // Create a panel with all 3 widgets
  var legendPanel = ui.Panel({
    widgets: [title, legend, labels],
    style: {position: 'bottom-center', padding: '8px 15px'}
  })
  return legendPanel
}
// Call the function to create a colorbar legend  
var colorBar = createColorBar('NDVI Values', palette, 0, 0.5)

Map.add(colorBar)

// Export the clipped image to your Google Drive account.
Export.image.toDrive({
  image: ndvi,
  description: 'NDVI_Afghanistan_2018_S2',
  folder: 'GEE_Export',
  scale: 10,
  maxPixels: 1e10,
  region: geometry

});

I've experimented with different scales and max pixels but I am stuck. I tried selecting a smaller area and eventually downloaded some images but they just showed up as blank. And I would like to keep the original area.


Solution

  • I had the same problem and i resolved it adding (in addiction to maxPixels) the command shardSize:2560. It increases the size in terms of pixels of the tiles in which the image is computed (256 by default). You can also choose the dimension of the entire image file with the command fileDimensions. Here's the link to see more in detail all the possible commands: https://developers.google.com/earth-engine/apidocs/export-image-todrive