2

I would like to export raster in a foreach loop with :

var landCover = ee.Image('MODIS/006/MCD12Q1/2016_01_01').select('LC_Prop1');
var countries = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017');

var Country_array = ['Kenya', 'Senegal', 
                     'Mozambique', 'Comoros', 
                     'France', 'Cambodia',
                     'Colombia','Gabon'];
Country_array.forEach(function(c) {
  print(c);
  var sel = countries.filter(ee.Filter.eq('country_na', c));
    var modis2017 = ee.Image(landCover)
                .clip(sel);

    Export.image.toDrive({
      image : modis2017,
      description: 'image'.concat('_', c),
      //maxPixels: 3784216672400,
      scale: 1000,
      crs : 'EPSG:4326',
      fileFormat: 'GeoTIFF'
      });

   // display
  Map.addLayer(sel, {}, 'shp'.concat('_', c));
  Map.addLayer(modis2017, {}, 'r'.concat('_', c));

});

but it produces empty (black) images. I don't understand why.

2
  • Does the export for a single country work, without the loop?
    – Kersten
    Jan 4, 2019 at 22:33
  • Yes it work outside de loop
    – delaye
    Jan 5, 2019 at 9:26

1 Answer 1

3

I don't understand why but it works whit region: sel.geometry().bounds() ... :

var landCover = ee.Image('MODIS/006/MCD12Q1/2016_01_01').select('LC_Prop1');
var countries = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017');

var Country_array = ['Kenya', 'Senegal', 
                     'Mozambique', 'Comoros', 
                     'France', 'Cambodia',
                     'Colombia','Gabon'];
Country_array.forEach(function(c) {
  print(c);
  var sel = countries.filter(ee.Filter.eq('country_na', c));
    var modis2017 = ee.Image(landCover)
                .clip(sel);

    Export.image.toDrive({
      image : modis2017,
      description: 'image'.concat('_', c),
      //maxPixels: 3784216672400,
      scale: 1000,
      crs : 'EPSG:4326',
      fileFormat: 'GeoTIFF',
      region: sel.geometry().bounds()
      });

   // display
  Map.addLayer(sel, {}, 'shp'.concat('_', c));
  Map.addLayer(modis2017, {}, 'r'.concat('_', c));

});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.