Let's say that I have a hypothetical study region and I just want to create a list object with all of the LULC classes within that region. How can a get it?
I got, for example, a MODIS LULC:
var ecoregions = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017');
var caatinga = ecoregions.filterMetadata('ECO_NAME', 'equals', 'Caatinga')
var cover = ee.Image('MODIS/051/MCD12Q1/2012_01_01').select('Land_Cover_Type_1')
.clip(caatinga.geometry());
Map.addLayer(cover, {0: 15}, 'cover');
Map.centerObject(cover, 5.5)
var list = ee.List(cover.get('Land_Cover_Type_1'))
print(list)
But all that I get is a "null" information
I want to use this information further to calculate the area of each class within that region. But usually, I just create a sequence with all putative possible values like:
var classes = ee.List.sequence(1, 15)
print(classes)
An object like classes
works just fine. However, not all classes between 1 and 15 are necessarily present and the outcome that I get is a table with empty columns for the inexistent classes. That wouldn't be a problem if I'm working with only a few empty classes, but in certain situations, I would like the outcome to have only the actually present classes without the burden to remove empty columns afterwards.
I feel like it should be something quite simple, but I couldn't figure it out yet. Any advice?