I am quite new to Google Earth Engine and Java scripting. I am delineating land cover data for an administrative area in Kenya (Samburu county) from the Copernicus Global Landcover 100m product. I've calculated the frequency & percentages for the different land cover classes in the county. I am trying to mask out each of the land cover classes and then do an NDVI time-series analysis for each of these land cover classes for my study area in Google Earth Engine.
How do I mask out the landcover classes?
Here is the code that I have scripted.
The link to the code is https://code.earthengine.google.com/?scriptPath=users%2Fwawerujohn%2Fhallo_world%3ASamburu_Landcover_100m_Copernicus%20(copy)
var globcover = ee.Image("COPERNICUS/Landcover/100m/Proba-V-C3/Global/2019")
.select('discrete_classification');
// Extract the landcover band
var landcover = globcover.select('discrete_classification');
// Clip the image to the polygon geometry
var landcover_roi = landcover.clip(geometry);
// Add a map layer of the landcover clipped to the polygon.
Map.addLayer(landcover_roi);
// Print out the frequency of landcover occurrence for the polygon.
var frequency = landcover.reduceRegion({
reducer:ee.Reducer.frequencyHistogram(),
geometry:geometry,
scale:1000
});
//var maskShrub = landcover_roi.updateMask(value.eq(20));
//Map.addLayer(maskShrub, {min: 0, max: 1, palette: palette}, 'Shrub only')
var dict = ee.Dictionary(frequency.get('discrete_classification'));
var sum = ee.Array(dict.values()).reduce(ee.Reducer.sum(),[0]).get([0]);
var new_dict = dict.map(function(k,v) {
return ee.Number(v).divide(sum).multiply(100);
});
print('Land Cover (%)',new_dict);
print('landcover frequency', frequency.get('discrete_classification'));
Map.setCenter(37, 1, 8);
Map.addLayer(globcover, {}, "Land Cover");
Export.image.toDrive({
image: landcover_roi,
description: 'Landcover',
scale: 100,
region: mask,
fileFormat: 'GeoTIFF',
formatOptions: {
cloudOptimized: true
}
});