2

I am trying to create a panel that shows a value on the map. The value should show the resulting value of an accuracy assessment(for instance: ConfusionMatrix.accuracy()). I am using the following piece of code:

var acc_val= ee.String(trainAccuracy.accuracy())

var legendTitle = ui.Label({
  value: 'Overall Accuracy:'+  acc_val , 
  style: {
    fontSize: '18px',
    margin: '0 0 4px 0',
    padding: '0'
    }
});
Map.add(panel);
panel.add(legendTitle);

where acc_val should be a number or string, but it shows a long list of characters.

This is what I get:

what I get:

This is what I expect:

What I expect:

The code is here.

1 Answer 1

2

You get this because you do client-side concatenation on acc_val, which is a server-side object. Read Client vs. Server in the Earth Engine docs for an explanation. You can convert acc_val to a client-side object with evaluate():

var acc_val = ee.String(trainAccuracy.accuracy()) // Server-side object

acc_val.evaluate(function(value) { // Turn acc_val into client-side object
  var legendTitle = ui.Label({
    value: 'Overall Accuracy: ' + value,
    style: {
      fontSize: '18px',
      margin: '0 0 4px 0',
      padding: '0'
    }
  });
  Map.add(panel);
  panel.add(legendTitle);
})

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.