0

In Earth Engine how can the bands generated through a stacking of an ImageCollection to a a multi-band image be named after the corresponding month-year?

I use the following code to stack the ImageCollection, but the bands are simply named sequentially with integer numbers.

def stackCollection(collection):
first = ee.Image(collection.first()).select([])
def appendBands(image, previous):
    return ee.Image(previous).addBands(image)
return ee.Image(collection.iterate(appendBands, first))

stacked = stackCollection(imageCollection)

0

You could add single band images to one image using the function toBands(), which renames the bands automatically for Landsat and Sentinel-2 images to their ID (which includes the date taken). See: Making stack from many images in Google Earth Engine?

If you would like to add the date in your function, you will have to look up in the image properties where the date is set. For Landsat images, it will be:

var dateString = ee.Date(image.get('system:time_start')).format('yyyy-MM-dd');

For Sentinel-2 images it will for example be:

var dateString = ee.Date(image.get('GENERATION_TIME')).format('yyyy-MM-dd');

You can then rename the bands in your function by changing 'YOUR_BAND_NAME':

var image = image.select('YOUR_BAND_NAME').rename(dateString)
0

I have found a workaround. This will rename each image of an imagecollection into the corresponding date. Tested with VIIRS, usure if it works without edits to the 'system:index' string with other imagecollections.

var arr = collection.map(function(im){ 
  return im.rename([im.get("system:index")])

})

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.