Google Earth Engine – How to Display ID of Each Image in Sentinel-2 Level 2A Image Collection

google-earth-enginegoogle-earth-engine-javascript-apisentinel-2

I need to work with Sentinel-2 MSI: MultiSpectral Instrument, Level-2A collection in Google Earth Engine, but I need the ID (according to the naming convention in this format: MMM_MSIXXX_YYYYMMDDHHMMSS_Nxxyy_ROOO_Txxxxx_

How can I keep or display the ID of each image in a Sentinel-2 Collection after applying a function to mask clouds, bounds filters and date filters. Because I only get the properties system:time_start and system:index (highlighted in yellow in the image below).

You can find the code in this link
image below

Best Answer

After applying a function, the image loses the original properties. maskS2clouds is doing that, not bounds and date filters as you mentioned.

The function copyProperties lets you preserve properties after applying functions.

The code you have preserves one property from the original image in this line (inside maskS2clouds function):

return image.updateMask(mask).divide(10000).copyProperties(image,['system:time_start']);

Yo can change that line preserving all properties:

return image.updateMask(mask).divide(10000).copyProperties(image);

Or preserving only granule ID (with time stamp - recommended for further analysis -):

return image
.updateMask(mask)
.divide(10000)
.copyProperties(image,['GRANULE_ID','system:time_start']);