I am working with MODIS-NDVI data (MODIS/006/MOD13Q1) in Google Earth Engine. I have a script which exports each image in the image collection for given area and time period. I need to upgrade script which will composite band by years to have a single file for each year. Later, I need to export them Google Drive. Could anyone please assist me on upgrading below shown code?

var col = ee.ImageCollection("MODIS/006/MOD13Q1")

var ExportCol = function(col, folder, scale, type,
                         nimg, maxPixels, region) {
    type = type || "float";
    nimg = nimg || 500;

    var colList = col.toList(nimg);
    var n = colList.size().getInfo();

    for (var i = 0; i < n; i++) {
      var img = ee.Image(colList.get(i));
      var id = img.id().getInfo();

      var imgtype = {"float":img.toFloat(), 

        description: id,
        folder: folder,
        fileNamePrefix: id,
        region: studyarea2,
        scale: scale,
        maxPixels: maxPixels})

  ExportCol(col, "NDVI_MODIS_NKz_KZ", 250);
  • What kind of composite are you aiming for - the mean value for each band and year? – Kersten Jun 22 '18 at 11:40
  • I would like to stack all layer in one year to single file like a bands and to be able export the stacked layers as single file – Sarvarbek Eltazarov Jun 22 '18 at 13:43

try this code: https://code.earthengine.google.com/9052c17efac7990cf1c5449654186d08


var col = ee.ImageCollection("MODIS/006/MOD13Q1")

// Functions to stack colletion series into image bands  

var stackCollection = function(collection) {
  var first = ee.Image(collection.first()).select([]);
  var appendBands = function(image, previous) 
  {return ee.Image(previous).addBands(image);};
  return ee.Image(collection.iterate(appendBands, first));};

// Function to generate mask for each Scene.

var getSceneMask = function(scene) {
  var dateString = ee.Date(scene.get('system:time_start')).format('yyyy-MM-dd');
  var mask = scene.select('NDVI').gt(-9999).updateMask(ee.Image(1));
  return mask.rename(dateString);};

//Stacked mask for collection

var MaskCol = stackCollection(col.map(getSceneMask));

// Generate a datelist for collection 

var datelist = ee.List(MaskCol.bandNames()).map(function(date){return ee.Date(date).format('yyyy-MM-dd')});


// Stack bands and rename by date  

var ndvi_stacked = stackCollection(col.select('NDVI')).divide(10000).rename(datelist);


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.