I'm stuck with an issue in google earth engine.

I'm working with MODIS Burned Area Monthly Global 500m, for a certain polygon area:

var MOD = ee.ImageCollection('MODIS/006/MCD64A1');
var MOD1 = MOD.filterDate('2005-06-21', '2005-09-31');
var MODlim1 = MOD.map(function(img) {return img.clip(lim)})

The problem is the image collection has three images (one for each month), and I need to convert this into a single image, which contains the burned area for three images in only one. Anyone knows what function can be helpful in this situation? I need to repeat this for every year (until 2018), so with a single image, it would be easier to analyze the data.

  • 1
    Are you planning to combine the data somehow? or you want just a 3 bands image? Sep 12, 2018 at 16:51
  • i want the three images that compose the image collection (one for each month), converts into one image that contains the data for the three (summary: three becoming one)
    – Vann
    Sep 12, 2018 at 23:46
  • Ok, but still not answering. You need one value per pixel? or 3 values per pixel? have you worked with raster images before? Sep 13, 2018 at 1:17
  • one value per pixel. yes I have (ENVI, ARCGIS, QGIS, etc).. I thought I've answered your question. no need to be so condescending
    – Vann
    Sep 13, 2018 at 2:49
  • Sorry, I am just trying to help. The problem here is that you have 3 values (one for each month) and you want just 1 value. Assuming that your interest is in the burnDate band of MCD64A1, what will be the only value for those 3 months? the latest date? Sep 13, 2018 at 3:29

1 Answer 1

// UPDATE: The easiest way is now toBands().
var merged = MOD1.toBands();

// For completeness, this is the iterate() way:
var mergeBands = function(image, previous) {
  return ee.Image(previous).addBands(image);

var merged = MOD1.iterate(mergeBands, ee.Image([]));
  • 1
    Great! everyday you learn something new =) I didn't know that using ee.Image([]) (an image with no bands) would make the loop start from the first image of the collection. Splitting the collection was a pain. Thanks! Sep 15, 2018 at 18:12
  • 1
    Some explanation about the code would be helpful. Sep 16, 2018 at 4:56
  • 2
    Learn more from the iterate() docs: the user guide and/or the API reference. Sep 17, 2018 at 3:07
  • I also obtained the result using: var merged = MOD1.iterate(mergeBands, MOD1.first());
    – shahryar
    Apr 12, 2020 at 20:31

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.