1

Here is an image collection [img1,img2,img3,img4,img5]. I want to get List or image collection [img1, img1+img2,img1+img2+img3, img1+img2+img3+img4, img1+img2+img3+img4+img5].

I tried to complete the following code https://code.earthengine.google.com/20763e4a37f2341558c2b7162f02eb83. But the result image collection b did not contain 'system:time_start'. I don't know how to modify my algorithm. Or you have a better way to get the accumulated image collection with 'system:time_start'.

var img1 = ee.Image(1).set('system:time_start','2001-01-01');
var img2 = ee.Image(2).set('system:time_start','2001-01-02');
var img3 = ee.Image(3).set('system:time_start','2001-01-03');
var img4 = ee.Image(4).set('system:time_start','2001-01-04');
var img5 = ee.Image(5).set('system:time_start','2001-01-05');
var image=ee.ImageCollection([img1,img2,img3,img4,img5]);
/*image = image.map(function(image) {
  return image.add(1);
});*/
var list = image.toList(image.size());

var t = ee.List(image.map(function(tt){
  return tt.get('system:time_start');
}))

var newList = list.slice(1);
newList = newList.iterate(function(data, list) {
  data = ee.Image(data);
  list = ee.List(list);
  list = list.add(data.add(ee.Image(list.get(list.size().subtract(1)))));
  return list;
}, ee.List([list.get(0)]));
var b = ee.ImageCollection(ee.List(newList).slice(1));


print(b) 
1

Following script creates a new collection with timestamp (collection_ts) from your old named variable image (now is collection).

var img1 = ee.Image(1).set('system:time_start','2001-01-01');
var img2 = ee.Image(2).set('system:time_start','2001-01-02');
var img3 = ee.Image(3).set('system:time_start','2001-01-03');
var img4 = ee.Image(4).set('system:time_start','2001-01-04');
var img5 = ee.Image(5).set('system:time_start','2001-01-05');

var collection = ee.ImageCollection([img1,img2,img3,img4,img5]); //this is a collection

var collection_ts = collection.map(function(img){
  var date = img.get('system:time_start');
  return img.set('system_time_start', date);
});

print(collection_ts);

var list = collection_ts.toList(collection_ts.size());

var newList = list.slice(1);

newList = newList.iterate(function(data, list) {
  data = ee.Image(data);
  list = ee.List(list);
  list = list.add(data.add(ee.Image(list.get(list.size().subtract(1)))));
  return list;
}, ee.List([list.get(0)]));

var b = ee.ImageCollection(ee.List(newList).slice(1));

print(b);

When you print collection_ts, it can be observed in Console Tab that it contains effectively a timestamp:

enter image description here

| improve this answer | |
  • Thank you very much for your answer. But the result collection(b) still has no ‘system:time_start’ or 'system_time_start' – YYu Mar 21 at 12:00
  • I didn't manipulate your collection b because I don't know what do you want to do with it. Now, you can "connect" it with collection_ts. – xunilk Mar 21 at 12:27
  • Thank you.I have found the solution – YYu Mar 22 at 12:24

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.