1

I am using the code below to export one image with 12 bands for year the year 2015, if want to generate the images for each year from 2000 on, is there any way to automate this to generate one image per year, without having to change the dates of the code each time?

// Export Burned Area Australia 
//

var col =  ee.ImageCollection("MODIS/006/MCD64A1")
             .filterDate('2015-01-01', '2016-01-01')
             .select('BurnDate');

// Define the regional bounds 
var region = ee.Geometry.Polygon(
        [[[139.81147500927887, -22.584034738321385],
          [139.81147500927887, -39.52984428265981],
          [155.19233438427887, -39.52984428265981],
          [155.19233438427887, -22.584034738321385]]], null, false);

Map.addLayer(region) 

// Clip and add a date band
var clipToRegion = function(img) {
  var dateString = ee.Date(img.get('system:time_start')).format('yyyy-MM-dd');
  var clipped = img.clip(region)
  return clipped.rename(dateString)
};

var burned_area = col.map(clipToRegion);
var scal = burned_area.first().projection().nominalScale();
var check = ee.Image(burned_area.first());
Map.addLayer(check, {palette: ['000000', '00FFFF'], max: 366}, 'check');
print('Scale', scal )

// Stack One layer by year 
//
var stackCollection = function(collection) {
  // Create an initial image.
  var first = ee.Image(collection.first()).select([]);

  // Write a function that appends a band to an image.
  var appendBands = function(image, previous) {
      var dateString = ee.Date(image.get('system:time_start')).format('yyyy-MM-dd');
      return ee.Image(previous).addBands(image);
  };
  return ee.Image(collection.iterate(appendBands, first));
};

var evi_img = stackCollection(burned_area);
print("EVI image stack",evi_img);

Export.image.toDrive({
  image: evi_img,
  description: 'BurnedAreaAustralia',
  scale: 463.3127165275,
  region: region,
  fileFormat: 'GeoTIFF',
  formatOptions: {
    cloudOptimized: true
  }
});



1 Answer 1

2

You can make a function of the complete script you have created. Than make a CLIENT-SIDE list of the years you are interested in, and map over that client-side list to make one export task for every year.

// create years and export for every year
var years = Array.apply(null, {length: 16}).map(Number.call, Number) // sequence of 16 numbers
            .map(function(number){
              return exportImagePerYear(col, number + 2000)}); // add 2000 for each year

In this script, the local function exportImagePerYear is your function, except for the part of the code which is needed for every image export (region and collection). See the link to the full code

Note you can use this function to start all exports at once.

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.