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

GEE计算遥感指数报错:Cannot read property 'normalizedDifference' of undefined

解决GEE中"Cannot read property 'normalizedDifference' of undefined"错误

错误原因

你代码里的var composite = addIndices(composite);存在变量引用错误:调用addIndices函数时,composite变量还未被定义和赋值,相当于给函数传入了undefined,函数内部尝试对undefined执行normalizedDifference方法,因此触发报错。

修复方案

将之前通过影像集处理得到的image变量(即均值合成后的Landsat影像)传入addIndices函数,替换未定义的composite参数即可。

修复后的完整代码

Map.addLayer(hjrb);
var image = ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")
.filterDate("2014-01-01", "2015-12-31")
.filterMetadata("CLOUD_COVER", "less_than", 1)
.filterBounds(hjrb)
.mean();
var visParamfalse = {bands: ["SR_B3","SR_B4","SR_B5"]};
Map.addLayer (image.clip(hjrb), visParamfalse, 'study2015');
Map.centerObject(hjrb, 8);

//indices
var addIndices = function(image){
  var gndvi = image.normalizedDifference(['SR_B5', 'SR_B3']).rename(['gndvi']);
  var ndbi = image.normalizedDifference(['SR_B5', 'SR_B4']).rename(['ndbi']);
  var ndwi = image.normalizedDifference(['SR_B3', 'SR_B5']).rename(['ndwi']);

  return image.addBands(gndvi).addBands(ndbi).addBands(ndwi);
};

// 修改此处:用已生成的image作为参数传入函数
var composite = addIndices(image);

补充说明

修复后,composite变量会成为包含原始波段+GNDVI、NDBI、NDWI指数波段的合成影像,可直接用于后续的监督分类流程。

内容的提问来源于stack exchange,提问作者idris wada

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 03:32:43