0

How can I get the different Class Tables show in the "Bands" tab on https://developers.google.com/earth-engine/datasets/catalog/MODIS_061_MCD12Q1 with the JavaScript API?

If I know the band I would like to use, "LC_Type1", how can I retrieve the list of classes that can be used to visualise this band (without adding the layer to a map)?

If I try to run ee.Image.evaluate() on the first image in the collection I get som information about the different bands (id, data_type, dimensions, crs and crs_transform), but it don't include the list of classes with color and descriptions.

1 Answers1

0

here is the approach I use for such case:

// Load the Land Cover dataset
var dataset = ee.ImageCollection('MODIS/061/MCD12Q1');

// Get the first image from the collection
var image = dataset.first();

// Load the class table asset
var classTable = ee.FeatureCollection('MODIS/061/MCD12Q1_LC_Type1_class_table');

// Filter the class table to match the LC_Type1 band
var classTableFiltered = classTable.filter(ee.Filter.eq('lc_property', 'LC_Type1'));

// Get the class names, colors, and descriptions
var classNames = classTableFiltered.aggregate_array('value');
var classColors = classTableFiltered.aggregate_array('color');
var classDescriptions = classTableFiltered.aggregate_array('description');

// Print the class information
classNames.getInfo(function(classNamesList) {
classColors.getInfo(function(classColorsList) {
    classDescriptions.getInfo(function(classDescriptionsList) {
    console.log('Class Names:', classNamesList);
    console.log('Class Colors:', classColorsList);
    console.log('Class Descriptions:', classDescriptionsList);
    });
});
});
Mohamed Mostafa
  • 520
  • 2
  • 10
  • Testing var classTable = ee.FeatureCollection('MODIS/061/MCD12Q1_LC_Type1_class_table') I get the error "Collection.loadTable: Collection asset 'MODIS/061/MCD12Q1_LC_Type1_class_table' not found." – Bjorn Sandvik Aug 08 '23 at 21:52