2013-05-07 106 views
3

我知道NDVI方程NDVI計算使用Python

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' 

什麼我做錯了任何想法?

+0

我只是做了這一點,但我們有一個傳感器來測量兩個頻段,所以我們從得到的值......這些都是一些熱圖什麼? – 2013-05-07 05:15:30

回答

2

如果用

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

更換

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

按照預期的腳本應該工作。

0

以下腳本從4波段NAIP圖像計算NDVI,其中波段4 = nIR,波段3 =紅色。你需要這個空間分析擴展。

請記住,Landsat TM波段4 = nIR &波段3 =紅色和Landsat 8波段5 = nIR和波段4 =紅色。 USGS Reference

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