• 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

    原始代码:

    1. // Importar imagem Landsat 8
    2. var image = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR/LC08_221077_20170411');
    3. // Centrar mapa
    4. Map.setCenter(-46.19804603400004,-12.026968211384917);
    5. // Obter bandas espectrais
    6. var nir = image.select('B5'); // Infravermelho próximo
    7. var red = image.select('B4'); // Vermelho
    8. var blue = image.select('B2'); // Azul
    9. var green = image.select('B3'); // Verde
    10. // Calcular índices de vegetação
    11. var ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI'); // NDVI
    12. var savi = nir.subtract(red).multiply(1.5).divide(nir.add(red).add(0.5)).rename('SAVI'); // SAVI
    13. var evi = nir.subtract(red).multiply(2.5).divide(nir.add(red.multiply(6)).subtract(blue.multiply(7.5)).add(1)).rename('EVI'); // EVI
    14. var wdvi = nir.subtract(red.multiply(0.87)).rename('WDVI'); // WDVI
    15. var gndvi = nir.subtract(green).divide(nir.add(green)).rename('GNDVI'); // GNDVI
    16. var grvi = green.divide(red).rename('GRVI'); // GRVI
    17. var gci = nir.divide(green).subtract(1).rename('GCI'); // GCI
    18. var pri = blue.subtract(green).divide(blue.add(green)).rename('PRI'); // PRI
    19. var tvi = nir.subtract(green).multiply(120).subtract(red.subtract(green).multiply(200)).multiply(0.5).add(0.5).rename('TVI'); // TVI
    20. 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
    21. var osavi = nir.subtract(red).divide(nir.add(red).add(0.16)).rename('OSAVI'); // OSAVI
    22. var mtvi1 = nir.subtract(green).multiply(1.2).subtract(red.subtract(green).multiply(2.5)).rename('MTVI1'); // MTVI1
    23. var mtvi2 = nir.divide(green).subtract(1.2).multiply(1.5).subtract(red.divide(green).subtract(2.5)).multiply(1.5).rename('MTVI2'); // MTVI2
    24. // Definir parâmetros de visualização dos índices
    25. var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'NDVI'}; // NDVI
    26. var saviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'SAVI'}; // SAVI
    27. var eviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'EVI'}; // EVI
    28. var wdviParams = {min: -0.1, max: 0.6, palette: ['blue', 'white', 'green'], bands: 'WDVI'}; // WDVI
    29. var gndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'GNDVI'}; // GNDVI
    30. var grviParams = {min: 0, max: 1, palette: ['red', 'yellow', 'green'], bands: 'GRVI'}; // GRVI
    31. var gciParams = {min: -0.5, max: 0.5, palette: ['red', 'white', 'green'], bands: 'GCI'}; // GCI
    32. var priParams = {min: -0.5, max: 0.5, palette: ['red', 'white', 'green'], bands: 'PRI'}; // PRI
    33. var tviParams = {min: 0, max: 1, palette: ['blue', 'white', 'green'], bands: 'TVI'}; // TVI
    34. var msaviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'MSAVI'}; // MSAVI
    35. var osaviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'OSAVI'}; // OSAVI
    36. var mtvi1Params = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'MTVI1'}; // MTVI1
    37. var mtvi2Params = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'MTVI2'}; // MTVI2
    38. // Adicionar camadas dos índices ao mapa
    39. Map.addLayer(ndvi, ndviParams, 'NDVI');
    40. Map.addLayer(savi, saviParams, 'SAVI');
    41. Map.addLayer(evi, eviParams, 'EVI');
    42. Map.addLayer(wdvi, wdviParams, 'WDVI');
    43. Map.addLayer(gndvi, gndviParams, 'GNDVI');
    44. Map.addLayer(grvi, grviParams, 'GRVI');
    45. Map.addLayer(gci, gciParams, 'GCI');
    46. Map.addLayer(pri, priParams, 'PRI');
    47. Map.addLayer(tvi, tviParams, 'TVI');
    48. Map.addLayer(msavi, msaviParams, 'MSAVI');
    49. Map.addLayer(osavi, osaviParams, 'OSAVI');
    50. Map.addLayer(mtvi1, mtvi1Params, 'MTVI1');
    51. Map.addLayer(mtvi2, mtvi2Params, 'MTVI2');

    修改后的代码:

    1. var geometry = /* color: #d63000 */ee.Geometry.Point([-46.19804603400004, -12.026968211384917]);
    2. // Importar imagem Landsat 8
    3. //var image = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR/LC08_221077_20170411');
    4. // Centrar mapa
    5. Map.setCenter(-46.19804603400004,-12.026968211384917);
    6. var image = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR').filterBounds(geometry).first();
    7. // Obter bandas espectrais
    8. var nir = image.select('B5'); // Infravermelho próximo
    9. var red = image.select('B4'); // Vermelho
    10. var blue = image.select('B2'); // Azul
    11. var green = image.select('B3'); // Verde
    12. // Calcular índices de vegetação
    13. var ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI'); // NDVI
    14. var savi = nir.subtract(red).multiply(1.5).divide(nir.add(red).add(0.5)).rename('SAVI'); // SAVI
    15. var evi = nir.subtract(red).multiply(2.5).divide(nir.add(red.multiply(6)).subtract(blue.multiply(7.5)).add(1)).rename('EVI'); // EVI
    16. var wdvi = nir.subtract(red.multiply(0.87)).rename('WDVI'); // WDVI
    17. var gndvi = nir.subtract(green).divide(nir.add(green)).rename('GNDVI'); // GNDVI
    18. var grvi = green.divide(red).rename('GRVI'); // GRVI
    19. var gci = nir.divide(green).subtract(1).rename('GCI'); // GCI
    20. var pri = blue.subtract(green).divide(blue.add(green)).rename('PRI'); // PRI
    21. var tvi = nir.subtract(green).multiply(120).subtract(red.subtract(green).multiply(200)).multiply(0.5).add(0.5).rename('TVI'); // TVI
    22. 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
    23. var osavi = nir.subtract(red).divide(nir.add(red).add(0.16)).rename('OSAVI'); // OSAVI
    24. var mtvi1 = nir.subtract(green).multiply(1.2).subtract(red.subtract(green).multiply(2.5)).rename('MTVI1'); // MTVI1
    25. var mtvi2 = nir.divide(green).subtract(1.2).multiply(1.5).subtract(red.divide(green).subtract(2.5)).multiply(1.5).rename('MTVI2'); // MTVI2
    26. // Definir parâmetros de visualização dos índices
    27. var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'NDVI'}; // NDVI
    28. var saviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'SAVI'}; // SAVI
    29. var eviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'EVI'}; // EVI
    30. var wdviParams = {min: -0.1, max: 0.6, palette: ['blue', 'white', 'green'], bands: 'WDVI'}; // WDVI
    31. var gndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'GNDVI'}; // GNDVI
    32. var grviParams = {min: 0, max: 1, palette: ['red', 'yellow', 'green'], bands: 'GRVI'}; // GRVI
    33. var gciParams = {min: -0.5, max: 0.5, palette: ['red', 'white', 'green'], bands: 'GCI'}; // GCI
    34. var priParams = {min: -0.5, max: 0.5, palette: ['red', 'white', 'green'], bands: 'PRI'}; // PRI
    35. var tviParams = {min: 0, max: 1, palette: ['blue', 'white', 'green'], bands: 'TVI'}; // TVI
    36. var msaviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'MSAVI'}; // MSAVI
    37. var osaviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'OSAVI'}; // OSAVI
    38. var mtvi1Params = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'MTVI1'}; // MTVI1
    39. var mtvi2Params = {min: -1, max: 1, palette: ['blue', 'white', 'green'], bands: 'MTVI2'}; // MTVI2
    40. // Adicionar camadas dos índices ao mapa
    41. Map.addLayer(ndvi, ndviParams, 'NDVI');
    42. Map.addLayer(savi, saviParams, 'SAVI');
    43. Map.addLayer(evi, eviParams, 'EVI');
    44. Map.addLayer(wdvi, wdviParams, 'WDVI');
    45. Map.addLayer(gndvi, gndviParams, 'GNDVI');
    46. Map.addLayer(grvi, grviParams, 'GRVI');
    47. Map.addLayer(gci, gciParams, 'GCI');
    48. Map.addLayer(pri, priParams, 'PRI');
    49. Map.addLayer(tvi, tviParams, 'TVI');
    50. Map.addLayer(msavi, msaviParams, 'MSAVI');
    51. Map.addLayer(osavi, osaviParams, 'OSAVI');
    52. Map.addLayer(mtvi1, mtvi1Params, 'MTVI1');
    53. Map.addLayer(mtvi2, mtvi2Params, 'MTVI2');

  • 相关阅读:
    【苹果群发】iMessage苹果推字符串访问权限,而我们在SSL推杆证书中的步骤相同
    【灵魂拷问:读取 excel 测试数据真的慢吗?】
    关于阅读《重构的时机和方法》这本书所带来的启发
    JMH-并发包分析
    JVM详解
    模糊搜索利器:Python的thefuzz模块详解
    18 张图带你彻底认识这些数据结构
    能ping通,TCP就一定能连通吗?
    Springboot启动流程核心知识点(二):bean的实例化过程
    国考省考行测:主旨题结构分析法,总分,分总,分分,分总分,总分总,主旨题错误选项的设置规律
  • 原文地址:https://blog.csdn.net/qq_31988139/article/details/134252645