Google Earth Engine – How to Fix ‘Error: Image.setDefaultProjection, Invalid Image Type’ when Exporting Image to Drive

google-earth-enginegoogle-earth-engine-javascript-apisentinel-2

Whenever I try to export to the drive the image gives me the following error:

Error: Image.setDefaultProjection, argument 'image': Invalid type.
Expected type: Image. Actual type: ImageCollection.

Here is my code.

var geometry = /* color: #d63000 */ee.Geometry.Polygon( [[[74.01142578125001, 14.03928427738163],
          [75.72529296875001, 11.489388290086518],
          [77.37324218750001, 11.446320285084074],
          [78.80146484375001, 12.82111821321301],
          [78.80146484375001, 13.334782405546143],
          [78.47187500000001, 13.762005499112181],
          [77.21943359375001, 14.741626710276806],
          [77.63691406250001, 15.907131677028499],
          [77.83466796875001, 18.38444661547079],
          [77.52705078125001, 18.65529832003967],
          [77.10957031250001, 18.488671081603027],
          [74.18720703125001, 16.876777270926873],
          [74.07734375000001, 16.22384925149735],
          [73.83564453125001, 14.932786866874553]]]);

var polygon = geometry;

var collection = ee.ImageCollection('COPERNICUS/S2')
 .filterDate('2021-04-01', '2021-04-30')
 .filterBounds(polygon);


var min = collection.min();

// Select the red, green and blue bands.
var result = min.select('B4', 'B3', 'B2');

Map.addLayer(result, {gain: '0.1, 0.1, 0.1', scale:20});
Map.setCenter(75, 15, 4);  //(lat, long,zoom)



//Export for karnataka region to drive

// Export the image, specifying scale and region.
Export.image.toDrive({
image: collection, //replace with your image name variable
description: 'karnataka_mosaic03_2021',
scale: 10,
maxPixels: 1e9,
region: geometry, //polygon name that you have drawn at step 1
folder:'mosaic_karnataka',
crs: "EPSG:32643"
});

Best Answer

The error and the comment in your export function already suggest what your problem is. Export.image.toDrive() expects a image, and not a collection of multiple images. So if you replace the collection with your result it should work:

// Export the image, specifying scale and region.
Export.image.toDrive({
image: result, //replace with your image name variable
description: 'karnataka_mosaic03_2021',
scale: 10,
maxPixels: 1e9,
region: geometry, //polygon name that you have drawn at step 1
folder:'mosaic_karnataka',
crs: "EPSG:32643"
});
Related Question