You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Earth Engine土地覆盖分类地图显示异常求助

土地覆盖分类地图显示异常问题
  • 脚本无语法错误,但地图仅显示黑色(Unknown类),未呈现各类土地覆盖分类
  • 正确效果可正常展示各类土地覆盖类别,当前效果全为黑色未知类
  • 与正确实现的差异:正确代码直接调用单景Image且无时间范围限制,本代码使用带时间过滤的ImageCollection并取中位数

用户代码

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'
];

// 定义可视化参数
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]));
  }
 
// 添加图例到地图
Map.add(legend);

问题原因与解决方法

核心问题

土地覆盖分类是离散类别编码(如1代表灌丛、2代表草本植被),median()是针对连续数值的聚合方法,会将类别编码当作连续数计算中间值,结果变成非整数的数值,不在你设置的min:1到max:17范围内,因此全部显示为Unknown类。

解决办法

对离散分类影像集合,应使用**众数(mode)**聚合,众数会选择时间序列中出现频率最高的类别,符合土地覆盖分类的逻辑:

// 替换原median()为mode()
var CountryLandCover = dataset.mode();

额外优化建议

  1. 优化计算效率:先聚合再裁剪,比先裁剪每景影像再聚合更高效:
// 修改数据集处理流程
var dataset = ee.ImageCollection('COPERNICUS/Landcover/100m/Proba-V-C3/Global')
  .filterDate('2015-01-01', '2015-12-31')
  .select('discrete_classification');

var CountryLandCover = dataset.mode().clip(countries);
  1. 匹配类别范围:Proba-V土地覆盖分类编码范围是1-22,你当前设置的max:17可根据需要调整,确保覆盖所有需展示的类别。

内容的提问来源于stack exchange,提问作者Isabel Schulze

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 21:25:09