I am currently trying to do a grouped reduction, but I am having trouble manipulating the outputs. The code calculates areas per land cover type and outputs a list of objects with two properties, 'code' i.e. land cover type and 'area', the area of the land cover in question. The issue is that I am having trouble filtering the output list, as I would like to access the area of each specific land cover without knowing the index.
The code is as follows:
// Load land cover
var lcStudy = ee.Image("COPERNICUS/Landcover/100m/Proba-V-C3/Global/2019")
.select('discrete_classification').clip(neighborhood);
// Add pixel area as a band to the Image
var lcStudyAreas = ee.Image.pixelArea().rename('area').addBands(lcStudy);
print(lcStudyAreas);
// Do a grouped reduction
var output = lcStudyAreas.reduceRegion({
reducer: ee.Reducer.sum().group({
groupField: 1,
groupName: 'code',
}),
geometry: neighborhood,
scale: 1000,
maxPixels: 1e13
}).get('groups');
print(output);
The issue is I would like to know, for example, the area of the land cover number 20 (shrubland). But when I haven't found the correct way to filter the list. Writing:
var shrubArea = ee.List(output).filter(ee.Filter.eq('code',20));
Produces an error:
List.filter: Filters used in List.filter should refer to the property named 'item'.
But replacing 'code' for 'item' produces an empty list.
Here is a link to the code: https://code.earthengine.google.com/b144b1c5645b69748576e7d426a3bb3b