错误:
这里的时错误原始的代码链接:
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
原始代码:
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');
修改后的代码:
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');
标签:function,XXX,nir,green,GEE,var,subtract,red,multiply From: https://blog.51cto.com/u_15654855/8368839