1

I have done a supervised classification. The output is an image collection. I cannot export it in drive. Here is the link

https://code.earthengine.google.com/ebd671bb75dde4892e3a7e14acdc7d4e

var maskL8 = function(image_m) {
  var qa = image_m.select('BQA');
  var mask = qa.bitwiseAnd(1 << 4).eq(0);
  return image_m.updateMask(mask);
};

var image_m = ee.Image(ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterBounds(roi)
.filterDate('2018-06-16', '2018-10-15')
.map(maskL8)
.median());
Map.addLayer(image_m, {bands: ['B5', 'B4', 'B3'], max: 0.3}, 'image_m');

var maskL8 = function(image_s) {
  var qa = image_s.select('BQA');
  var mask = qa.bitwiseAnd(1 << 4).eq(0);
  return image_s.updateMask(mask);
};

var image_s = ee.Image(ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterBounds(roi)
.filterDate('2018-03-16', '2018-05-15')
.map(maskL8)
.median());
Map.addLayer(image_s, {bands: ['B5', 'B4', 'B3'], max: 0.3}, 'image_s');

var maskL8 = function(image_w) {
  var qa = image_w.select('BQA');
  var mask = qa.bitwiseAnd(1 << 4).eq(0);
  return image_w.updateMask(mask);
};

var image_w = ee.Image(ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterBounds(roi)
.filterDate('2017-11-16', '2018-02-15')
.map(maskL8)
.median());
Map.addLayer(image_w, {bands: ['B5', 'B4', 'B3'], max: 0.3}, 'image_w');


var mergedCollection = image_m.addBands(image_s.addBands(image_w));
print('mergedCollection: ', mergedCollection);
Map.addLayer(mergedCollection, {bands: ['B5', 'B4', 'B3'], max: 0.3}, 'mergedCollection');

//merge
var newfc = Waterbody.merge(Wetland).merge(Vegetation).merge(Agricultural).merge(Builtup).merge(BarrenLand);
print(newfc);

//create training data
var bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7'];
var training = mergedCollection.select(bands).sampleRegions({
  collection: newfc, 
  properties: ['landcover'], 
  scale: 30
  });
print(training);

//Train the classifier
var classifier = ee.Classifier.cart().train({
  features: training, 
  classProperty: 'landcover', 
  inputProperties: bands
  });

//Run the classification
var classified = mergedCollection.select(bands).classify(classifier); 

//Display classification
Map.centerObject(newfc, 11);
Map.addLayer(mergedCollection, 
{bands: ['B4', 'B3', 'B2'], max: 0.3}, 
'Landsat image');

Map.addLayer(classified, 
{min: 1, max: 6, palette: ['003EFF', '638A61', 'E34314', 'C3C056', '96E6E5', '95F905' ]}, 
'classification');
Map.addLayer(newfc)


// Export the image, specifying scale and region.
Export.image.toDrive({
  image: classified.select(classified),
  description: 'imageToDriveExample',
  scale: 500,
  region: roi
});

It is showing the following error

Error: Image.select, argument 'bandSelectors': Invalid type. Expected: List. Actual: Image<[classification]>

1

The output of classified isn't an ImageCollection object, is an Image object (see print(classified);) and this image has only 1 band. You can use either:

// Export the image, specifying scale and region.
Export.image.toDrive({
  image: classified,
  description: 'imageToDriveExample',
  scale: 30,
  region: roi
});

or

// Export the image, specifying scale and region.
Export.image.toDrive({
  image: classified.select('classification'),
  description: 'imageToDriveExample',
  scale: 30,
  region: roi
});

to export results

  • Thank you. Ir works. The exported image is fully black. What is the problem? Would you please help me? – Shihab Nur Aug 19 at 20:44
  • Which software are you using to display the image? – aldo_tapia Aug 19 at 20:51
  • Oh! I was trying to open it directly. Now it works in Arc GIS. Thank you so much – Shihab Nur Aug 19 at 21:14
  • 1
    You're welcome. If you want, you can close the topic accepting this answer (tick in the left side of the answer) – aldo_tapia Aug 19 at 21:16

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.