我知道 NDVI 方程是

NDVI = (NIR — VIS)/(NIR + VIS)

我正在尝试使用 python 计算它。到目前为止我有这个:
inRaster = ('Landsat.tif')
out_NDVI_file = ('NDVI.tif')

red = arcpy.Describe(inRaster+'/Band_3')
NIR = arcpy.Describe(inRaster+'/Band_4')

num = arcpy.sa.Float(NIR-red)
denom = arcpy.sa.Foat(NIR+red)
NDVI = arcpy.sa.Divide(num, denom)

NDVI.Save(out_NDVI_file)

但我收到此错误消息,
Traceback (most recent call last):
  File "F:\abc\def.py", line 32, in <module>
    num = arcpy.sa.Float(NIR-red)
TypeError: unsupported operand type(s) for -: 'geoprocessing describe data object' and 'geoprocessing describe data object'

关于我做错了什么的任何想法?

最佳答案

如果你更换

red = arcpy.Describe(inRaster+'/Band_3')
NIR = arcpy.Describe(inRaster+'/Band_4')


red = arcpy.sa.Raster(inRaster+'/Band_3')
NIR = arcpy.sa.Raster(inRaster+'/Band_4')

您的脚本应该按预期工作。

关于python - 使用 Python 计算 NDVI,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16411468/

10-12 19:27