0

I'm working on exporting MCD12C1 image from Google Earth Engine. However, when I run the code, it reminds me this message:

Error: Image.setDefaultProjection, argument 'image': Invalid type. Expected type: Image. Actual type: ImageCollection. (Error code: 3).

I cannot find where the problem is.

enter image description here

Here's my code for exporting the image :


var startdate = '2018-01-01';
var enddate = '2020-12-31';

var MCD12C1data = MCD12C1.filterDate(startdate,enddate)
                  .filterBounds(roi)
                  .map(selectVetypes)
                  .map(Clip_ROI)
                  // .map(maskconfidence);
print(MCD12C1data)

Map.addLayer(MCD12C1data,{min:0,max:16},'MCD')
Map.addLayer(roi.style({color:'black',fillColor:'00000000'}),{},'roi')

function Clip_ROI(image){
  return image.clip(roi)
}

function maskconfidence(image){
  var percent = image.select('Majority_Land_Cover_Type_1')
  var mask = percent.gt(50) // Percent cover of each IGBP class at each pixel
  return image.updateMask(mask);
}

function selectVetypes(image) {
  var types = image.select('Majority_Land_Cover_Type_1').rename('vegetationtypes')  
  return types.copyProperties(image, image.propertyNames());
}

Export.image.toDrive({
    image: MCD12C1data.select('vegetationtypes'),
    description: 'MCD12C1_masked',
    folder: "data",
    region: roi,
    scale: 5600,
    crs: 'EPSG:4326',
    maxPixels: 1e13
});

1 Answer 1

1

As the error states, you are trying to export an ee.ImageCollection while Export.image.toDrive supports only ee.Image type.

You have two options:

  1. convert the image collection to image computing a stat like mean or median
  2. export the image collection

If you want to export the image collection, this site has tackled this topic before:

So, for your case, just load the awesome batch exporter from Rodrigo Principe:

var MCD12C1 = ee.ImageCollection("MODIS/061/MCD12C1");
var batch = require('users/fitoprincipe/geetools:batch')

var startdate = '2018-01-01';
var enddate = '2020-12-31';

var MCD12C1data = MCD12C1.filterDate(startdate,enddate)
                  .filterBounds(roi)
                  .map(selectVetypes)
                  .map(Clip_ROI)
                  // .map(maskconfidence);
print(MCD12C1data)

Map.addLayer(MCD12C1data,{min:0,max:16},'MCD')

function Clip_ROI(image){
  return image.clip(roi)
}

function maskconfidence(image){
  var percent = image.select('Majority_Land_Cover_Type_1')
  var mask = percent.gt(50) // Percent cover of each IGBP class at each pixel
  return image.updateMask(mask);
}

function selectVetypes(image) {
  var types = image.select('Majority_Land_Cover_Type_1').rename('vegetationtypes')  
  return types.copyProperties(image, image.propertyNames());
}

batch.Download.ImageCollection.toDrive(MCD12C1data.select('vegetationtypes'),
                'MCD12C1_masked', 
                {scale: 5600, 
                 crs: 'EPSG:4326',
                 region: roi})
0

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.