直接使用arcgis python 计算多波段图像的NDVI值。
代码如下
import arcpy, string from arcpy import env from arcpy.sa import* arcpy.CheckOutExtension("spatial")#检查spatial权限 env.workspace = r"G:\ESRI\work\code temp"#工作空间 #input = arcpy.GetParameterAsText(0) #result = arcpy.GetParameterAsText(1) input = "landsat.tif"#输入图像 result = "result.tif"#输出结果 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)#保存结果