I'm using Landsat imagery in Google Earth Engine and am attempting to convert an image collection to a multiband image. However, before doing so I do two things:

  1. I mosaic the images by date so that there is only one Landsat image per day
  2. I sort the image collection by date (system:id) so that it goes from oldest to newest rather than being sorted by the Landsat satellite.

This works correctly, but when I use .toBands to convert this into a multiband image the output is gibberish. I need an output multiband image where each band is the correct date for that image in the mosaicked and sorted image collection.

I've included pictures of the problem I'm having and the relevant code at the bottom.

In my example, the Landsat collection contains 560 images.

enter image description here

After mosaicking I have 352 images, but they are not in temporal order:

enter image description here

Sorting correctly sorts the image collection by date: enter image description here

But when I use .toBands to convert the sorted image collection into a single multiband image, the output is gibberish: enter image description here

//mosaic images by date
function mosaicByDate(imcol){
  var imlist = imcol.toList(imcol.size())

  var unique_dates = imlist.map(function(im){
    return ee.Image(im).date().format("YYYY-MM-dd")

  var mosaic_imlist = unique_dates.map(function(d){
    d = ee.Date(d)

    var im = imcol
      .filterDate(d, d.advance(1, "day"))

    return im.set(
        "system:time_start", d.millis(), 
        "system:id", d.format("YYYYMMdd"))

  return ee.ImageCollection(mosaic_imlist)

//apply the mosaic to the Landsat image collections    
var ic_NDVI = mosaicByDate(NDVIuse)

//Sort by date. The image collection is now sorted by date instead of by Landsat satellite    
var ic_NDVI_sorted = ic_NDVI.sort('system:id')

//Convert the image collection into a single multiband image. The output is gibberish.
var merged_LST = ic_NDVI_sorted.toBands();
print('Sorted multiband',merged_NDVI)

1 Answer 1


I'm assuming that the mosaics are in ascending chronological order. But the band naming is 'gibberish' because you've set your unique identifier (yyyymmdd) to the system:id property rather than system:index. system:index is the property that .toBands uses to name each band. The documentation is perhaps a little misleading because it is referring to system:index when it says 'id':

Output bands are named by prefixing the existing band names with the image id from which it came


So replace the two cases where you use system:id with system:index.

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.