1

I'm trying to make a supervised classification program in GEE. But it gives me the error: Layer name is not a string: ee.Classifier

// Define a region in which to generate a sample of the input.
var region = ee.Geometry.Rectangle(-71, -1.5, -67, 2.2);

// Display the sample region.
Map.setCenter(-68.50, 0.43, 7);

//select sentinel image
var img = ee.Image('COPERNICUS/S2/20170813T145731_20170813T145912_T19NEA');

//merging samples
var amostra = clareira.merge(agua).merge(mata).merge(nuvem);
//Map.addLayer(amostra);

//selecting bands
var bandas = ['B4','B3','B2'];

//creating training set
var training = img.select(bandas).sampleRegions({
  collection:amostra,
  properties:['class'],
  scale:10
});

//selecting classification algorithm
var classificacao = ee.Classifier.cart().train({
  features: training, 
  classProperty:['class'],
  inputProperties:bandas});

var result = img.select(bandas).classify(classificacao);

//Map.addLayer(img, {bands:'B4,B3,B2'});
Map.addLayer(result, {min: 0, max:3, palette:['magenta', 'blue', 'green', 'white']},classificacao);
3

As said in the error, the layer name (the third argument in Map.addLayer) should be a string. change your last line to this:

Map.addLayer(result, {min: 0, max:3, palette:['magenta', 'blue', 'green', 'white']},'classificacao');

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.