i wanted to do a land cover classification. The script has no errors, but the map is displayed incorrectly. Instead of the different classifications being displayed, I see the map only in black (unknown)this Images shows how it looks now, this is how it should look correctly, the difference is only here: var dataset = ee.Image("COPERNICUS/Landcover/100m/Proba-V-C3/Global/2019").select('discrete_classification'); var CountryLandCover = dataset.clip(countries); --> here i don´t have a specific time period
var countries = ee.FeatureCollection('FAO/GAUL_SIMPLIFIED_500m/2015/level2')
.filterMetadata('ADM0_NAME', 'equals', 'Eritrea');
var clip_AOI = function(image){
return image.clip(countries);
};
var dataset = ee.ImageCollection('COPERNICUS/Landcover/100m/Proba-V-C3/Global')
.filterDate('2015-01-01', '2015-12-31')
.select('discrete_classification')
.map(clip_AOI);
var CountryLandCover = dataset.median();
Map.addLayer(CountryLandCover, LandCoverVis, 'Country Land Cover');
// Center the map on Eritrea
Map.centerObject(countries);
// Create a panel for legend
var legend = ui.Panel({
style: {
position: 'bottom-left',
padding: '8px 15px'
}
});
// Create the title for legend
var legendTitle = ui.Label({
value: 'Land Cover',
style: {
fontWeight: 'bold',
fontSize: '18px',
margin: '0 0 4px 0',
padding: '0'
}
});
legend.add(legendTitle);
var loading = ui.Label('Loading legend...', {margin: '2px 0 4px 0'});
legend.add(loading);
// Create and style the first row in the legend
var makeRow = function(color, name) {
// Create the color box in the legend
var colorBox = ui.Label({
style: {
backgroundColor: '#' + color,
padding: '8px',
margin: '0 0 4px 0'
}
});
// Create the label for the description text
var description = ui.Label({
value: name,
style: {margin: '0 0 4px 6px'}
});
return ui.Panel({
widgets: [colorBox, description],
layout: ui.Panel.Layout.Flow('horizontal')
});
};
// Add the list of color codes and class names of land use classes
var palette = [
'282828', 'FFBB22', 'FFFF4C', 'F096FF', 'FA0000', 'B4B4B4', 'F0F0F0',
'0032C8', '0096A0', 'FAE6A0', '58481F', '009900', '70663E', '00CC00',
'4E751F', '007800', '666000', '8DB400', '8D7400', 'A0DC00', '929900',
'648C00', '000080'
];
var names = [
'Unknown',
'Shrubs',
'Herbaceous vegetation',
'Cultivated and managed vegetation / agriculture',
'Urban / built up',
'Bare / sparse vegetation',
'Snow and ice',
'Permanent water bodies',
'Herbaceous wetland',
//'Moss and lichen',
'Closed forest, evergreen needle leaf',
'Closed forest, evergreen broad leaf',
'Closed forest, deciduous needle leaf',
'Closed forest, deciduous broad leaf',
'Closed forest, mixed',
'Closed forest, not matching any of the other definitions',
'Open forest, evergreen needle leaf',
'Open forest, evergreen broad leaf',
'Open forest, deciduous needle leaf',
'Open forest, deciduous broad leaf',
'Open forest, mixed',
'Open forest, not matching any of the other definitions',
//'Oceans, seas'
];
// Visualisierungsparameter definieren
var LandCoverVis = {
min: 1.0,
max: 17.0,
palette: palette,
};
loading.style().set('shown', false);
for (var i = 0; i < names.length; i++) {
legend.add(makeRow(palette[i], names[i]));
}
// Legende in die Karte hinzufügen
Map.add(legend);
You are loading an ImageCollection. With your time period selected it contains the only Image though. Usually I check it with the simple line:
which gives the detailed info on right hand side in Console window.
Thus, for proper visualization you define which image you want, taking the first one for instance:
Next, remove the line
It doesn't make any sense since there is the only image
And then feed the dataset itself to the layer:
Hope, it helps!