0

I have a piece of code:

var grid = ee.FeatureCollection("users/quangig/kt2"),
    rgbVis = {"min":0,"max":0.3,"bands":["B4","B3","B2"]};

function maskS2clouds(image) {
  var qa = image.select('QA60');
// Bits 10 and 11 are clouads and cirrus, respectively.
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;
// Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
            .and(qa.bitwiseAnd(cirrusBitMask).eq(0));
   return image.updateMask(mask).divide(10000);
}

var col = ee.ImageCollection("COPERNICUS/S2")
           .filterDate('2016-01-01','2020-12-31')
           //.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
           .filterBounds(grid)
           .map(maskS2clouds)
           //.selct('vis-red', 'vis-green', 'vis-blue')
           .median();

Map.addLayer(col, rgbVis, 'Mosaic');
Map.addLayer(grid, {}, 'Grid');
Map.centerObject(grid, 8);

var seq = ee.List.sequence(1, ee.Number(grid.size()));
print(seq);

var split = seq.map(function(x){
   var fil = grid.filterMetadata('grid', 'equals', x);
   var sCol = col.clip(fil);
   return sCol.visualize(rgbVis)
              .set('grid', x);
});

var final_col = ee.ImageCollection.fromImages(split);
print(final_col);

Map.addLayer(final_col.first());

for(var a = 1; a < final_col.size().getInfo() + 1; a++){
 // print(a);
 print(final_col.filterMetadata('grid', 'equals', a).mosaic())
  Export.image.toDrive({
  image: final_col.filterMetadata('grid', 'equals', a).mosaic().select(['vis-red', 'vis-green', 'vis-blue']),
  description:'Image'+'_'+a,
  folder: 'GEE/GRID',
  scale: 10,
  maxPixels:1e13,
  });
}

enter image description here

After clicking download Google Drive, there are many small files. Why are there so many small files? How can there be only 1 file when exporting to Google Drive?

enter image description here

0

That's EE tiling them for you, so you don't have to work with too large files. You can control this tile size with the fileDimensions property in Export.image.toDrive(). Specify it big enough to fit the image you're exporting and you'll only get a single file.

From the docs:

fileDimensions (List|Number, optional):

The dimensions in pixels of each image file, if the image is too large to fit in a single file. May specify a single number to indicate a square shape, or an array of two dimensions to indicate (width,height). Note that the image will still be clipped to the overall image dimensions. Must be a multiple of shardSize.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.