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

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

错误:

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

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

原始代码:

// Importar imagem Landsat 8
var image = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR/LC08_221077_20170411');
// Centrar mapa 
Map.setCenter(-46.19804603400004,-12.026968211384917);
// 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');

修改后的代码:

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

相关文章
|
7月前
Google Earth Engine(GEE)——ndvi.gt is not a function
Google Earth Engine(GEE)——ndvi.gt is not a function
71 2
|
7月前
GEE错误——Line 2: ee.Image(...).filterBounds is not a function
GEE错误——Line 2: ee.Image(...).filterBounds is not a function
98 0
|
7月前
|
JavaScript 前端开发
GEE错误——gee错误Line 35: nir.subtract is not a function
GEE错误——gee错误Line 35: nir.subtract is not a function
86 0
|
7月前
Google Earth Engine(GEE)——当你无法进行两个图像相减的时候发生错误lst2020.subtract is not a function
Google Earth Engine(GEE)——当你无法进行两个图像相减的时候发生错误lst2020.subtract is not a function
83 0
|
JavaScript
$("#XXX").click()和$("#YYY").on("click","指定的元素",function(){});的区别(jQuery动态绑定事件)
      //绑定 下一页 的点击事件 $("a[aria-label='Next']").click(function(){ $("a[aria-label='Previous']").
1452 0
|
1月前
|
中间件 Docker Python
【Azure Function】FTP上传了Python Function文件后,无法在门户页面加载函数的问题
通过FTP上传Python Function至Azure云后,出现函数列表无法加载的问题。经排查,发现是由于`requirements.txt`中的依赖包未被正确安装。解决方法为:在本地安装依赖包到`.python_packages/lib/site-packages`目录,再将该目录内容上传至云上的`wwwroot`目录,并重启应用。最终成功加载函数列表。
|
2月前
|
JavaScript
箭头函数与普通函数(function)的区别
箭头函数是ES6引入的新特性,与传统函数相比,它有更简洁的语法,且没有自己的this、arguments、super或new.target绑定,而是继承自外层作用域。箭头函数不适用于构造函数,不能使用new关键字调用。
|
2月前
|
数据可视化 开发者 索引
详解Wireshark LUA插件函数:function p_myproto.dissector(buffer, pinfo, tree)
在 Wireshark 中,LUA 插件通过 `function p_myproto.dissector(buffer, pinfo, tree)` 扩展协议解析能力,解析自定义应用层协议。参数 `buffer` 是 `PacketBuffer` 类型,表示原始数据包内容;`pinfo` 是 `ProtoInfo` 类型,包含数据包元信息(如 IP 地址、协议类型等);`tree` 是
89 1
|
2月前
|
JavaScript
箭头函数与普通函数(function)的区别
箭头函数是ES6引入的新语法,相比传统函数表达式更简洁,且没有自己的this、arguments、super或new.target绑定,而是继承自外层作用域。这使得箭头函数在处理回调和闭包时更加灵活方便。
|
2月前
|
C++ 容器
函数对象包装器function和bind机制
函数对象包装器function和bind机制
23 0

热门文章

最新文章