微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

monthlyRainfall.filter(...).first 不是一个函数

如何解决monthlyRainfall.filter(...).first 不是一个函数

https://code.earthengine.google.com/18914d58d2f193bf206e108774902ce5

var months = ee.List.sequence(1,12)

...

var monthlyRainfall = months.map(function(month) {
    var filtered = monthlyCol.filter(ee.Filter.eq('month',month))
    var monthlyMean = filtered.mean()
    return monthlyMean.set('month',month)
})

...

var deviation = months.map(function(month) {
  var longTermMean = ee.Image(monthlyRainfall
    .filter(ee.Filter.eq('month',month)).first())
  var monthlyObserved = ee.Image(observedRainfall
    .filter(ee.Filter.eq('month',month)).first())
  var deviation = (monthlyObserved.subtract(longTermMean)
    .divide(longTermMean)).multiply(100)
    .set('month',month)
  return deviation
})

我收到错误或行号。 88 在我上面提到的链接中。

Line 88: monthlyRainfall.filter(...).first is not a function

我为这个问题找到的解决方案是使用 ee.Image。但即使在使用它之后,我也面临同样的错误。请帮助我如何度过难关。

解决方法

monthlyRainfallee.List,而不是 ee.ImageCollection。它们在某些方面很相似,但 ee.List 没有 .first() 操作(而是您可以编写 .get(0))。

过滤器在列表和集合上的工作方式也不同。在这种情况下,为了使其按您想要的方式工作,您应该将您的 List 转换为 ImageCollection。改变

var monthlyRainfall = months.map(function(month) {
    var filtered = monthlyCol.filter(ee.Filter.eq('month',month))
    var monthlyMean = filtered.mean()
    return monthlyMean.set('month',month)
})

应用ee.ImageCollection(...),它将图像列表转换为一个ImageCollection:

var monthlyRainfall = ee.ImageCollection(months.map(function(month) {
    var filtered = monthlyCol.filter(ee.Filter.eq('month',month));
    var monthlyMean = filtered.mean();
    return monthlyMean.set('month',month);
}));

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。