filtered.normalizedDifference is not a function???如何解决

filtered 是一个 ImageCollection 对象,而不是一个单独的 Image 对象。

!!!注意!!!

   normalizedDifference 是一个 Image 对象的方法,而不是 ImageCollection 对象的方法。因此,不能直接在 ImageCollection 对象上调用 normalizedDifference 方法。

为了计算 NDVI,你需要对 ImageCollection 中的每一张影像应用 normalizedDifference 方法。使用 .map() 方法来实现这一点!!!!!!!!!!!!!

这里是修改后的代码,它使用 .map() 方法对 ImageCollection 中的每一张影像计算 NDVI:

//---------------------------去云处理函数
function maskS2clouds(image) {
  var qa = image.select('QA60')
  var cloudBitMask = 1 << 10;
  var cirrusBitMask = 1 << 11;
  var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(
             qa.bitwiseAnd(cirrusBitMask).eq(0))
  return image.updateMask(mask)
      .select("B.*")
      .copyProperties(image, ["system:time_start"])
}

//-------------第一步:选择研究区,对影像数据进行去云,获得去云影像filtered;
var s2 = ee.ImageCollection("COPERNICUS/S2"); 
var geometry = ee.FeatureCollection("projects/helical-parity-405906/assets/yangben/crop_6")
Map.addLayer(geometry, {color: 'red'}, 'Farm')
Map.centerObject(geometry)

var startDate = ee.Date('2022-9-1')
var endDate = ee.Date('2023-11-30') 

var filtered = s2
  .filter(ee.Filter.date(startDate, endDate))
  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
  .filter(ee.Filter.bounds(geometry))
var filtered = filtered.map(maskS2clouds);
print('filtered',filtered);

///-------------------------计算NDVI,并获得ndvi数据集合ndviCol-----------------------/




//定义光谱指数
    var NDVI = filtered.normalizedDifference(['B8', 'B4']).toFloat().rename('NDVI');







-----------修改之后的代码------------//





// 定义光谱指数计算函数  
function calculateNDVI(image) {  
  var ndvi = image.normalizedDifference(['B8', 'B4']).toFloat().rename('NDVI');  
  return ndvi;  
}  
  
// 计算NDVI,并获得ndvi数据集合ndviCol  
var ndviCol = filtered.map(calculateNDVI);  
  
print('ndviCol', ndviCol);

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值