1

i want to compute area from a classification in Google earth engine so i use the group to compute it, then the result is like this

enter image description here

How can i get the single sum value from a class: 0 ? then define it as a new variable

1 Answer 1

1

Thats a dictionary containing 1 item ('groups') which is a list of dictionaries, each containing two items ('class' and 'sum').

var list = ee.List(ee.Dictionary(result).get('groups'))
var group0 = ee.Dictionary(list.get(0))
var sum = group0.get('sum')

But if you're going to do something with all of the groups, it might be better to convert the list of dictionaries into two lists of classes and sums:

var list = ee.List(result.get('groups'))
var classes = list.map(function(d) {
  return ee.Dictionary(d).get('class')
})
var sums = list.map(function(d) {
  return ee.Dictionary(d).get('sum')
})
1
  • this is work, just add the print in the script "print (sums.get(0))" Aug 12, 2021 at 8:11

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.