Earth Engine error: Error: Image.select, argument 'bandSelectors':

by Shihab Nur   Last Updated August 19, 2019 20:22 PM

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]>



Answers 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

aldo_tapia
aldo_tapia
August 19, 2019 20:13 PM

Related Questions



Classification of stacking image

Updated July 19, 2019 11:22 AM

Divide into grid and Mosaic using google earth?

Updated July 21, 2015 14:09 PM

Crop classification in Earth Engine

Updated June 19, 2019 10:22 AM