[GIS] Filter and show images from an imageCollection in Google Earth Engine

cloud covergoogle-earth-engine

once filtered an imageCollection in Google Earth Engine, how can I add as layers the images resulting by the filter process?

I need to show all the images (S2_L2A) available for a specific point (I've already filetered the collection using a geometry) in a specific time range (aready done) and with a CLOUDY_PIXEL_PERCENTAGE less than 5%.

this is my script

var PNA: Point(15.90,38.12) 
var S2L2A: imageCollection"Sentinel-2 MSI: MultiSpectral Instrument, Level-2A"
var start = ee.Date('2018-01-01');
var finish = ee.Date('2019-10-01'); 
var imageSet = S2L2A.filterBounds(PNA).filterDate(start, finish).filterMetadata('CLOUDY_PIXEL_PERCENTAGE','less_than', 5); 
var count = imageSet.size(); 
print ('size of collection imageSet', count);

Now…How can I add as layers the resulting images?

Best Answer

It might be worth going through the GEE documents for some scripting: https://developers.google.com/earth-engine/

You'll end up with an ImageCollection (in your example 39 images) which you either need to reduce to 1 image by selecting the first image with .first()

If you trully want to add all images you need to create an featureCollection from your imageCollection and map over that a plotting function.

var PNA= ee.Geometry.Point(15.90,38.12) 
var S2L2A= ee.ImageCollection('COPERNICUS/S2_SR')
var start = ee.Date('2018-01-01');
var finish = ee.Date('2019-10-01'); 
var imageSet = S2L2A.filterBounds(PNA).filterDate(start, finish).filterMetadata('CLOUDY_PIXEL_PERCENTAGE','less_than', 5); 
var count = imageSet.size(); 
print ('size of collection imageSet', count);

// This is where you just select one image
var image = imageSet.first()
var imageVisParam = {"opacity":1,"bands":["B4","B3","B2"],"min":-468,"max":1228,"gamma":1};
Map.addLayer(image, imageVisParam, 'first image')

var imageSetCollection = imageSet.toList(count)

print(imageSetCollection)

ee.List.sequence(0,ee.Number(count.subtract(1))).getInfo()
.map(function(img){
  // print(img)

  var image = ee.Image(imageSetCollection.get(img))

  Map.addLayer(image, imageVisParam)
})
Related Question