0

I am trying to preview all rasters separately within a date range from an ImageCollection and then export the required raster to a drive. As of now, I am doing this by changing the date range multiple times which is really time-consuming.

var dist = ee.FeatureCollection("users/tilok/aoi");
var s2=ee.ImageCollection("COPERNICUS/S2_SR").filterDate('2019-11-01','2020-03-31').select(['B2','B3','B4','B8']).filterBounds(dist).mosaic().clip(dist);
print(s2a);

Map.addLayer (s2a,{bands:['B8','B4','B3',],max:5000});
Map.centerObject(dist, 07);
Export.image.toDrive({
  image: s2a,
  description: 'aoi_15mar2020',
  scale: 10,
  region: dist,
  maxPixels: 10e9
});

1 Answer 1

2

You can do this with client-side iteration. The below script evaluate a client-side array with the collection image ids, iterate over the ids. For each id, the corresponding image is located from the collection, the image is added to the map and exported. You still have to click the Run buttons under the Tasks tab.

var aoi = ee.Geometry.Point([0, 10]).buffer(1000)
Map.centerObject(aoi)
var collection = ee.ImageCollection("COPERNICUS/S2_SR_HARMONIZED")
  .filterBounds(aoi)
  .limit(10)
  
collection.aggregate_array('system:index')
  .evaluate(function (indexes) {
    indexes.forEach(function (index) {
      var image = collection
        .filter(ee.Filter.eq('system:index', index))
        .first()
        .clip(aoi)
      var description = 'image-' + index.replace(/[^\w]/, '_')
      Map.addLayer(image, {bands: 'B8,B4,B3', max: 5000}, description)
      Export.image.toDrive({
        image: image.select('B4'),
        description: description,
        scale: 10,
        maxPixels: 1e13,
        region: aoi,
      });      
    })
})

https://code.earthengine.google.com/b2f24e621e4137248d719bc3bd9abd0b

1
  • This is exactly what I was looking for and it works. Thank you @Daniel Jun 9, 2022 at 14:28

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.