Google Earth Engine get single value area from group object
google-earth-engine
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
How can i get the single sum value from a class: 0 ? then define it as a new variable
Best Answer
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')
})
But I do not recommend to do it directly like that because there are a lot of small areas and it'll take too long to process (may be it won't do it). You could process it a bit more in GEE, like filtering by count property or apply a focal_mode or something, or you could download the raster and do the process locally with a raster to vector algorithm.
No easy easy way to compute variable importance (yet) but you could try computing your accuracy multiple times, withholding one column each time. The largest decrease in accuracy will correspond to withholding the most important variable. then repeat leaving that one in and withholding the other N-1 columns, 1 at a time. etc.
Best Answer
Thats a dictionary containing 1 item ('groups') which is a list of dictionaries, each containing two items ('class' and '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: