0

Normally when I run this code I get the least cloudy image but I want to know what the other images are.

I use this code:

    var image = ee.ImageCollection('COPERNICUS/S2')
        .filterBounds(PuntoAbast2)
        .filterDate('2018-07-01','2018-07-02')
        .sort('CLOUD_COVER', false);
    var mejorImagen = ee.Image(image.sort('CLOUD_COVER').first());

With the set dates I get only one image but If I extend the date range I will get more, but this code only will return one image.

0

Be careful, you are not getting the least cloudy image that way, because CLOUD_COVER is not a property of Sentinel 2 Images. The correct property is CLOUD_COVERAGE_ASSESSMENT. With that clear, the second issue is that you are filtering the collection by one day and one point, so you won't get more than one image. If you make the date range wider you'll get an ImageCollection with many images ordered by cloud cover. Then you can get whichever you want:

var image = ee.ImageCollection('COPERNICUS/S2')
              .filterBounds(PuntoAbast2)
              .filterDate('2018-03-01','2018-07-02')
              //.sort('CLOUD_COVER', false); // false will order it descending
              .sort('CLOUD_COVERAGE_ASSESSMENT')

var mejorImagen = ee.Image(image.first());

print(image.size())

var listaImagenes = image.toList(image.size())
var segundaMejorImagen = ee.Image(listaImagenes.get(1))
var terceraMejorImagen = ee.Image(listaImagenes.get(3))

print('mejorImagen', mejorImagen.get('CLOUD_COVERAGE_ASSESSMENT'))
print('segundaMejorImagen', segundaMejorImagen.get('CLOUD_COVERAGE_ASSESSMENT'))

var all = listaImagenes.map(function(img){
  return ee.Image(img).get('CLOUD_COVERAGE_ASSESSMENT')
})
print('All:', all)

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.