Google Earth Engine – How to Download CSV of Dates from ImageCollection

google-earth-enginegoogle-earth-engine-javascript-api

I need to download a CSV file containing the acquisition date of each Sentinel-2 image in a featureCollection. I filtered the following featureCollection:

var startDate = ee.Date('2020-01-01');
var endDate = startDate.advance(1, 'year');

var s2L2A_rawData = ee.ImageCollection("COPERNICUS/S2_SR_HARMONIZED")
                  .filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 100)
                  .filter(ee.Filter.inList('MGRS_TILE', ['30SYJ']))
                  .filterDate(startDate, endDate)
                  .filterBounds(geometry);

print('Sentinel-2 L2A raw data', s2L2A_rawData);

How can I download a CSV with the date of each image to work the data locally?

Best Answer

Here is a solution which extracts the 'sysem:time_end' property using aggregate_array, converts the list into a FeatureCollection and downloads it to Google Drive using Export.table.toDrive:

var startDate = ee.Date('2020-01-01');
var endDate = startDate.advance(1, 'year');

var s2L2A_rawData = ee.ImageCollection("COPERNICUS/S2_SR_HARMONIZED")
                  .filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 100)
                  .filter(ee.Filter.inList('MGRS_TILE', ['30SYJ']))
                  .filterDate(startDate, endDate)
                  .filterBounds(geometry);

print('Sentinel-2 L2A raw data: ', s2L2A_rawData);

var property = 'system:time_end';
var dates = s2L2A_rawData.aggregate_array(property);

print('Sentinel-2 time serie dates: ', dates);

var dates_featureCollection = ee.FeatureCollection(dates
                                .map(function(element){
                                return ee.Feature(null,{property:element})}));

Export.table.toDrive({
  collection: dates_featureCollection,
  folder: 'Test_Folder',
  description:'dates',
  fileFormat: 'CSV'
});

Alternatively you can copy the values from dates list in GeoJSON format and paste it into your own text document, as shown in the image below:

enter image description here

Note that dates are stored in Unix Time.