I'm stacking all the images from Sentinel-2A from the L1C image collection, but when viewing the images beforehand, I see that there are duplicates images, same imaging date but different processing dates.


features: List (182 elements)
0: Image COPERNICUS/S2/20150820T082006_20150820T082942_T36RYV (1 band)
1: Image COPERNICUS/S2/20150820T082006_20160929T004310_T36RYV (1 band)
2: Image COPERNICUS/S2/20150830T082006_20150830T082754_T36RYV (1 band)
3: Image COPERNICUS/S2/20150830T082006_20161006T204405_T36RYV (1 band)
4: Image COPERNICUS/S2/20150830T082754_20160405T115445_T36RYV (1 band)
5: Image COPERNICUS/S2/20150909T081736_20150909T082324_T36RYV (1 band)
6: Image COPERNICUS/S2/20150909T081736_20161014T144949_T36RYV (1 band)
7: Image COPERNICUS/S2/20150919T081736_20150919T082756_T36RYV (1 band)
8: Image COPERNICUS/S2/20150919T081736_20161022T211502_T36RYV (1 band)
9: Image COPERNICUS/S2/20150929T081736_20150929T082542_T36RYV (1 band)

As you can see, most of the images appear 2 times, some even 3 times. So I want to filter out these images, and retain unique dates with the most recent processing date.

I'm not sure id there are any differences in the values, but to be on the safe side I don't want to reduce images together, but filter them out.

1 Answer 1


You can compare the ImageCollection with a List of Images and generate a specific property and filter.

var sentinel = ee.ImageCollection("COPERNICUS/S2")
    .filter(ee.Filter.eq('MGRS_TILE', "36RYV"))

//Generate a List to compare dates var lista = sentinel.toList(sentinel.size())

var imagen = ee.Image(lista.get(0)) //Add in the end of the list a dummy image lista = lista.add(imagen)

var detectar_duplicador = function(imagen){ var esduplicado = ee.String("") var numero = lista.indexOf(imagen) var imagen1 = ee.Image(lista.get(numero.add(1))) //Compare the image(0) in the ImageCollection with the image(1) in the List var fecha1 = imagen.date().format("Y-M-d") var fecha2 = imagen1.date().format("Y-M-d") var estado = ee.Algorithms.IsEqual(fecha1,fecha2) esduplicado = ee.String(ee.Algorithms.If({condition: estado, trueCase: "duplicado",
falseCase: "no duplicado"}));
return imagen.set({"duplicado": esduplicado}) }

sentinel = sentinel.map(detectar_duplicador) sentinel = sentinel.filter(ee.Filter.eq("duplicado","no duplicado")); print(sentinel)

Link to script: https://code.earthengine.google.com/1cd3f276faa9e52ba0913981344aa33d

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.