(Updated: 2023-08-14)
A method to estimate Earth Engine interactice server-to-client image data request size.
var geometry = ee.Geometry.Polygon(
[[[-123.61064453125, 45.977647428626796],
[-123.61064453125, 45.47145566980041],
[-120.940966796875, 45.47145566980041],
[-120.940966796875, 45.977647428626796]]], null, false);
// Estimate the download size, assumes all bands are same type.
function getSize(img, region, scale, crs, dataType) {
var bytes = {
'8bit': 1 + 1,
'16bit': 2 + 1,
'32bit': 4 + 1,
'64bit': 8 + 1
};
var bounds = region.bounds(0.01, crs);
var nPixels = img.select(0).unmask(0).clip(bounds)
.reduceRegion({
reducer: ee.Reducer.count(),
geometry: bounds,
scale: scale,
crs: crs,
maxPixels: 1e13
}).values().getNumber(0);
var nBands = img.bandNames().size();
var size = nPixels.multiply(nBands).multiply(bytes[dataType]);
return size;
}
// Mock image.
var img = ee.Image([1]).toByte();
// Export settings.
var scale = 30;
var crs = 'EPSG:4326';
var dataType = '8bit';
// Estimate the size of the download.
var sizeTest = getSize(img, geometry, scale, crs, dataType);
print('Estimated size (bytes)', sizeTest);
print('Estimated size (mb)', sizeTest.divide(1e6));
// Get the Download URL.
var url = img.getDownloadURL({
region: geometry,
scale: scale,
crs: crs,
format: 'GEO_TIFF'
});
print('Download URL', url);