2

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?

2 Answers 2

2

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.

1

Another simple way is:

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);

Export.table.toDrive({
  collection:s2L2A_rawData,
  folder: 'S2SR_test_dates',
  description:'images',
  selectors:['system:index'],
  fileFormat: 'csv'
})

you can change the property "system:index to "system":time_end"

2
  • Brilliant! This is the most direct way to do it. The selectors argument is very useful.
    – sermomon
    Commented Jan 2, 2023 at 19:30
  • 1
    you can also add other properties, something like selectors:['system:index','CLOUDY_PIXEL_PERCENTAGE','VEGETATION_PERCENTAGE']) . Enjoy it ;) . Commented Jan 2, 2023 at 19:52

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.