0

I loaded multiple images from Landsat 5 and Landsat 7 onto my Google Earth engine, from 1988 until 2022 for my region of interest. I'm trying to export these images individually to Google Drive as GeoTIFF files. I'm a little stuck on how to do so. Here is my code:

var cloudMaskL457 = function(image) {
var qa = image.select('pixel_qa');
var cloud = qa.bitwiseAnd(1 << 5)
            .and(qa.bitwiseAnd(1 << 7))
            .or(qa.bitwiseAnd(1 << 3));
var mask2 = image.mask().reduce(ee.Reducer.min());
return image.updateMask(cloud.not()).updateMask(mask2);
};

var l5 = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
              .filterDate('1984-01-01', '2011-12-31') 
              .map(cloudMaskL457)
              .filterBounds(aoi)
              .map(function(a){
                return a.set('year', ee.Image(a).date().get('year'))
              })

var l7 = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR')
              .filterDate('2012-01-01', '2022-12-31')
              .map(cloudMaskL457)
              .filterBounds(aoi)
              .map(function(a){
                return a.set('year', ee.Image(a).date().get('year'))
              })

var list = ee.List([])

for(var a=1984; a < 2023; a++) {

if(a < 2012) {

var fill5 = l5.filterMetadata('year', 'equals', a).median()
var l5final = fill5.set('year', a)
                   .set('product', 'l5')
                   
list=list.add(l5final)

} else { 

var fill7 = l7.filterMetadata('year', 'equals', a).median()
var l7final = fill7.set('year', a)
                   .set('product', 'l7')

list=list.add(l7final)
}


print(list)

var finalCol = ee.ImageCollection(list).map(function(a) {
            return a.set('bands', ee.Image(a).bandNames().length())
          })
          .filterMetadata('bands','equals', 11) 
          
print(finalCol)

for(var a = 1988; a < 2023; a++) {
Map.addLayer(finalCol.filterMetadata('year', 'equals', a), imageVisParam, 'Year'+' '+a, false)
}

enter image description here

1 Answer 1

0

You can export the image collection using Rodrigo Principe's batch module grom geetools:

var batch = require('users/fitoprincipe/geetools:batch');

batch.Download.ImageCollection.toDrive(finalCol, 'collection output', {
  scale: 30,
  region: aoi
});

Although trying to export the whole collection would take more memory than available, so try to export by year ranges

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.