4

我知道 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'

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

4

2 回答 2

4

如果你更换

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

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

于 2013-08-27T10:30:51.217 回答
1

以下脚本根据 4 波段 NAIP 影像计算 NDVI,其中波段 4 = nIR,波段 3 = 红色。为此,您需要空间分析扩展。

请记住,Landsat TM 波段 4 = nIR 和波段 3 = 红色和 Landsat 8 波段 5 = nIR 和波段 4 = 红色。 美国地质调查局参考

# Calculates NDVI from multispectral imagery

import arcpy, string

from arcpy import env
from arcpy.sa import*

arcpy.CheckOutExtension("spatial")

env.workspace = r'C:\Your\workspace'

input = r'C:\Your\raster.tif'

result = "outputName.tif"

# You may need to change the band combinations.  
# This is for 4-band NAIP imagery or Landsat TM.
NIR = input + "\Band_4"
Red = input + "\Band_3"

NIR_out = "NIR.tif"
Red_out = "Red.tif"

arcpy.CopyRaster_management(NIR,NIR_out)
arcpy.CopyRaster_management(Red, Red_out)

Num = arcpy.sa.Float(Raster(NIR_out) - Raster(Red_out))
Denom = arcpy.sa.Float(Raster(NIR_out) + Raster(Red_out))
NIR_eq = arcpy.sa.Divide(Num, Denom)

NIR_eq.save(result)
于 2013-12-31T20:39:26.907 回答