首页 > 其他分享 >GEE错误——XXX is not a function,如何解决这个问题?

GEE错误——XXX is not a function,如何解决这个问题?

时间:2023-11-14 14:32:22浏览次数:44  
标签:function XXX nir green GEE var subtract red multiply


错误:

这里的时错误原始的代码链接:

https://code.earthengine.google.com/4bf0975a41e14d0c40e01925c6f3cf2a

这里主要的问题时这个单一影像不存在:

ImageCollection (Error)

ImageCollection.load: ImageCollection asset 'LANDSAT/LC08/C01/T1_SR/LC08_221077_20170411' not found (does not exist or caller does not have access).

而表面的问题是

Line 16: nir.subtract is not a function

GEE错误——XXX is not a function,如何解决这个问题?_错误

 

原始代码:

var geometry = /* color: #d63000 */ee.Geometry.Point([-46.19804603400004, -12.026968211384917]);
// Importar imagem Landsat 8
//var image = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR/LC08_221077_20170411');
// Centrar mapa 
Map.setCenter(-46.19804603400004,-12.026968211384917);
var image = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR').filterBounds(geometry).first();

// Obter bandas espectrais
var nir = image.select('B5'); // Infravermelho próximo
var red = image.select('B4'); // Vermelho
var blue = image.select('B2'); // Azul
var green = image.select('B3'); // Verde

// Calcular índices de vegetação
var ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI'); // NDVI
var savi = nir.subtract(red).multiply(1.5).divide(nir.add(red).add(0.5)).rename('SAVI'); // SAVI
var evi = nir.subtract(red).multiply(2.5).divide(nir.add(red.multiply(6)).subtract(blue.multiply(7.5)).add(1)).rename('EVI'); // EVI
var wdvi = nir.subtract(red.multiply(0.87)).rename('WDVI'); // WDVI
var gndvi = nir.subtract(green).divide(nir.add(green)).rename('GNDVI'); // GNDVI
var grvi = green.divide(red).rename('GRVI'); // GRVI
var gci = nir.divide(green).subtract(1).rename('GCI'); // GCI
var pri = blue.subtract(green).divide(blue.add(green)).rename('PRI'); // PRI
var tvi = nir.subtract(green).multiply(120).subtract(red.subtract(green).multiply(200)).multiply(0.5).add(0.5).rename('TVI'); // TVI
var msavi = nir.multiply(2).add(1).subtract(ee.Image.constant(2).multiply(nir.add(1)).pow(2).subtract(ee.Image.constant(8).multiply(nir.subtract(red))).sqrt()).multiply(0.5).rename('MSAVI'); // MSAVI
var osavi = nir.subtract(red).divide(nir.add(red).add(0.16)).rename('OSAVI'); // OSAVI
var mtvi1 = nir.subtract(green).multiply(1.2).subtract(red.subtract(green).multiply(2.5)).rename('MTVI1'); // MTVI1
var mtvi2 = nir.divide(green).subtract(1.2).multiply(1.5).subtract(red.divide(green).subtract(2.5)).multiply(1.5).rename('MTVI2'); // MTVI2

// Definir parâmetros de visualização dos índices
var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'NDVI'}; // NDVI
var saviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'SAVI'}; // SAVI
var eviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'EVI'}; // EVI
var wdviParams = {min: -0.1, max: 0.6, palette: ['blue', 'white', 'green'], bands: 'WDVI'}; // WDVI
var gndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'GNDVI'}; // GNDVI
var grviParams = {min: 0, max: 1, palette: ['red', 'yellow', 'green'], bands: 'GRVI'}; // GRVI
var gciParams = {min: -0.5, max: 0.5, palette: ['red', 'white', 'green'], bands: 'GCI'}; // GCI
var priParams = {min: -0.5, max: 0.5, palette: ['red', 'white', 'green'], bands: 'PRI'}; // PRI
var tviParams = {min: 0, max: 1, palette: ['blue', 'white', 'green'], bands: 'TVI'}; // TVI
var msaviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'MSAVI'}; // MSAVI
var osaviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'OSAVI'}; // OSAVI
var mtvi1Params = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'MTVI1'}; // MTVI1
var mtvi2Params = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'MTVI2'}; // MTVI2

// Adicionar camadas dos índices ao mapa
Map.addLayer(ndvi, ndviParams, 'NDVI');
Map.addLayer(savi, saviParams, 'SAVI');
Map.addLayer(evi, eviParams, 'EVI');
Map.addLayer(wdvi, wdviParams, 'WDVI');
Map.addLayer(gndvi, gndviParams, 'GNDVI');
Map.addLayer(grvi, grviParams, 'GRVI');
Map.addLayer(gci, gciParams, 'GCI');
Map.addLayer(pri, priParams, 'PRI');
Map.addLayer(tvi, tviParams, 'TVI');
Map.addLayer(msavi, msaviParams, 'MSAVI');
Map.addLayer(osavi, osaviParams, 'OSAVI');
Map.addLayer(mtvi1, mtvi1Params, 'MTVI1');
Map.addLayer(mtvi2, mtvi2Params, 'MTVI2');

GEE错误——XXX is not a function,如何解决这个问题?_错误_02

修改后的代码:

var geometry = /* color: #d63000 */ee.Geometry.Point([-46.19804603400004, -12.026968211384917]);
// Importar imagem Landsat 8
//var image = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR/LC08_221077_20170411');
// Centrar mapa 
Map.setCenter(-46.19804603400004,-12.026968211384917);
var image = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR').filterBounds(geometry).first();

// Obter bandas espectrais
var nir = image.select('B5'); // Infravermelho próximo
var red = image.select('B4'); // Vermelho
var blue = image.select('B2'); // Azul
var green = image.select('B3'); // Verde

// Calcular índices de vegetação
var ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI'); // NDVI
var savi = nir.subtract(red).multiply(1.5).divide(nir.add(red).add(0.5)).rename('SAVI'); // SAVI
var evi = nir.subtract(red).multiply(2.5).divide(nir.add(red.multiply(6)).subtract(blue.multiply(7.5)).add(1)).rename('EVI'); // EVI
var wdvi = nir.subtract(red.multiply(0.87)).rename('WDVI'); // WDVI
var gndvi = nir.subtract(green).divide(nir.add(green)).rename('GNDVI'); // GNDVI
var grvi = green.divide(red).rename('GRVI'); // GRVI
var gci = nir.divide(green).subtract(1).rename('GCI'); // GCI
var pri = blue.subtract(green).divide(blue.add(green)).rename('PRI'); // PRI
var tvi = nir.subtract(green).multiply(120).subtract(red.subtract(green).multiply(200)).multiply(0.5).add(0.5).rename('TVI'); // TVI
var msavi = nir.multiply(2).add(1).subtract(ee.Image.constant(2).multiply(nir.add(1)).pow(2).subtract(ee.Image.constant(8).multiply(nir.subtract(red))).sqrt()).multiply(0.5).rename('MSAVI'); // MSAVI
var osavi = nir.subtract(red).divide(nir.add(red).add(0.16)).rename('OSAVI'); // OSAVI
var mtvi1 = nir.subtract(green).multiply(1.2).subtract(red.subtract(green).multiply(2.5)).rename('MTVI1'); // MTVI1
var mtvi2 = nir.divide(green).subtract(1.2).multiply(1.5).subtract(red.divide(green).subtract(2.5)).multiply(1.5).rename('MTVI2'); // MTVI2

// Definir parâmetros de visualização dos índices
var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'NDVI'}; // NDVI
var saviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'SAVI'}; // SAVI
var eviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'EVI'}; // EVI
var wdviParams = {min: -0.1, max: 0.6, palette: ['blue', 'white', 'green'], bands: 'WDVI'}; // WDVI
var gndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'GNDVI'}; // GNDVI
var grviParams = {min: 0, max: 1, palette: ['red', 'yellow', 'green'], bands: 'GRVI'}; // GRVI
var gciParams = {min: -0.5, max: 0.5, palette: ['red', 'white', 'green'], bands: 'GCI'}; // GCI
var priParams = {min: -0.5, max: 0.5, palette: ['red', 'white', 'green'], bands: 'PRI'}; // PRI
var tviParams = {min: 0, max: 1, palette: ['blue', 'white', 'green'], bands: 'TVI'}; // TVI
var msaviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'MSAVI'}; // MSAVI
var osaviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'OSAVI'}; // OSAVI
var mtvi1Params = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'MTVI1'}; // MTVI1
var mtvi2Params = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'MTVI2'}; // MTVI2

// Adicionar camadas dos índices ao mapa
Map.addLayer(ndvi, ndviParams, 'NDVI');
Map.addLayer(savi, saviParams, 'SAVI');
Map.addLayer(evi, eviParams, 'EVI');
Map.addLayer(wdvi, wdviParams, 'WDVI');
Map.addLayer(gndvi, gndviParams, 'GNDVI');
Map.addLayer(grvi, grviParams, 'GRVI');
Map.addLayer(gci, gciParams, 'GCI');
Map.addLayer(pri, priParams, 'PRI');
Map.addLayer(tvi, tviParams, 'TVI');
Map.addLayer(msavi, msaviParams, 'MSAVI');
Map.addLayer(osavi, osaviParams, 'OSAVI');
Map.addLayer(mtvi1, mtvi1Params, 'MTVI1');
Map.addLayer(mtvi2, mtvi2Params, 'MTVI2');

 

GEE错误——XXX is not a function,如何解决这个问题?_error_03

标签:function,XXX,nir,green,GEE,var,subtract,red,multiply
From: https://blog.51cto.com/u_15654855/8368839

相关文章

  • GEE数据集——2019、2020、2021、2022和2023年全球固定宽带和移动(蜂窝)网络性能Shapefi
    全球固定宽带和移动(蜂窝)网络性能¶全球固定宽带和移动(蜂窝)网络性能,分配给缩放级别16网络墨卡托图块(赤道处约610.8米x610.8米)。数据以Shapefile格式和ApacheParquet格式提供,其几何形状以众所周知的文本(WKT)表示,投影在EPSG:4326中。下载速度、上传速度和延迟是通过......
  • Ubuntu18.04 打开终端报错: ERROR: ld.so: object ‘xxx.so‘ from LD_PRELOAD cannot
    1、问题现象在文件界面打开终端的时候,突然发现开头有一堆报错ERROR:ld.so:object'./envlib.so'fromLD_PRELOADcannotbepreloaded(cannotopensharedobjectfile):ignored.ERROR:ld.so:object'./libharfbuzz.so.0'fromLD_PRELOADcannotbepreloaded(cannotope......
  • Function 函数式接口 处理if else过多的问题
    使用注解@FunctionalInterface标识,并且只包含一个抽象方法的接口是函数式接口。函数式接口主要分为Supplier供给型函数、Consumer消费型函数、Runnable无参无返回型函数和Function有参有返回型函数 处理if分支操作1、定义函数定义一个抛出异常的形式的函数式接口,这个接口......
  • 解决Azure function部署问题
    最近在AzureChina遇到了一个问题,大概现象是这样,我们用的runtime是python的,创建好function之后,在尝试往function上部署代码时遇到一些奇怪的现象,试了各种方法将代码部署到function上,都会遇到一些问题1.vscodeextension-报错Encounteredanerror7:15:31AMaz-mim-xxxxxx:Synci......
  • 编程最佳外挂:批量数据分析与可视化,CodeGeeX工具箱一键完成
    ChatGLM3代模型的CodeInterpreter能力,本周已经在VSCode里的CodeGeeX插件产品中,以开发者工具箱的产品形态上线。下图以VSCode插件为例:在CodeGeeX的侧边栏,和智能问答AskCodeGeeX并列出现的工具箱标签,用户登录后就可以直接打开使用。CodeInterpreter曾被称为ChatGPT最强外挂。现......
  • Git push到gerrit时报错change xxx closed
    Gitpush到gerrit时报错changexxxclosed报错日志:Tossh://xxxx![remoterejected]HEAD->refs/for/master(changehttp://xxxxm/+/96107closed)可以看到这个提交已经closed了,而change-Id未更改。即使用了已经合入的change-Id,在一次push的时候远端判断此change-Id......
  • c++ function使用
    一、function介绍funciotn是从c++11开始支持的特性,使用它需要包含<functional>头文件在cppreference中解释为:类模板std::function是一个通用的多态函数包装器。std::function的实例可以对任何可以调用的目标实体进行存储、复制、和调用操作,这些目标实体包括普通函数、Lambda表达......
  • 方法只能写在类里面,类外面的是函数 ; 定义函数只能function a(){} 或者 var a = funct
    下列哪几项可以创建函数?Afunction=myFunction(){……..}BfunctionmyFunction(){…...}Cmyfunction=function(){…….}DmyFunction(){….}正确答案:BCBC不谈,我说一下DD这个语法定义的是方法(method)。因为这种写法只能在class里生效,所以D这个function始终是跟一个object......
  • 解决:tcpdump -w xxxxx.cap 提示 Permission denied
    出现的如题所示问题。经过多次调试查找资料,找到了一种好用的方法。解决方案1:我们只需进入/tmp所在的目录下,然后执行tcpdump命令即可解决。例如:解决方案2:将文件写入指定目录下,正常是可以利用参数-w将采集的文件写入指定的文件目录下,但是往往会出现如上图所示的错误。这时......
  • Redis Functions 介绍之二
    首先,让我们先回顾一下上一篇讲的在RedisFunctions中关于将key的名字作为参数和非key名字作为参数的区别,先看下面的例子。首先,我们先在一个Lua脚本文件mylib.lua中定义如下的库和函数。//--------------------mylib.lua文件开始-----------//#!luaname=myliblocalfunct......