0

I have to print all the images (layers) of ImageCollection because it is easier to select manually the best image. Is it possible?

var point = ee.Geometry.Point([8.73727, 45.81165]);

// Import the S-2 image collection.
var S2 = ee.ImageCollection("COPERNICUS/S2_SR")


// VISUALIZZO IN ORDINE DECRESCENTE 
// LE IMMAGINI CON UNA PERCENTUALE DI PIXEL NUVOLOSI SOTTO IL 50%

var image = ee.Image(
  S2.filterBounds(point)
    .filterDate('2019-01-01', '2019-01-31')
    .filter('CLOUDY_PIXEL_PERCENTAGE < 50')
    .sort('CLOUDY_PIXEL_PERCENTAGE')
);
print(image) [8 images]

// Display the result.
Map.addLayer(image, Param, 'RGB image');

1 Answer 1

0

You can use for to make a loop on the client side and be able to use Map.addLayer. To select each image in its order of cloud percentage, you should transform the image collection into a list and then extract each image according to its index in this list.

// Display the results.
// Start with i = 0, end in i = the size of the image collection -1
// each step do i = i + 1
for(var i = 0; i <= imageCol.size().subtract(1).getInfo(); i++){
  // Convert image collection to list so you can get images by index.
  // Need to indicate the size of the image collection to convert to list
  // Get images in cloudiness order with get
  // Cast resulting object as image
  var resul = ee.Image(imageCol.toList(imageCol.size()).get(i));
  // Print to console
  print('image ' +i, resul);
  // Add image to Map 
  Map.addLayer(resul, 
  {
    bands: ['B4', 'B3', 'B2'],
    min: 200,
    max: 1700
  }, 'RGB image '+i);
}

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.