2014-11-06 57 views
0

這可能看起來微不足道,但我似乎可以跟蹤這個錯誤,而且我對Python非常非常新,但不是編程。從互聯網上閱讀了一下,我想我的問題是.dat ENVI圖像文件不被讀作「描述對象」。但是,我怎麼才能讓它被讀取?我可能需要它來閱讀標題信息,任何解決方案?Python Arcpy.describe麻煩閱讀ENVI.dat

這裏是我的代碼:

import arcpy #make sure you run the python associated with ArcGIS 
import os 

filepath = 'filepath' 
filename = 'filename' 
band_names = range(1,225) 

# Path creation 
in_folder = filepath + os.sep + 'ENVI' 
out_folder = filepath + os.sep + 'GeoTIFF' # preferably an empty folder 

# input multiband raster 
in_ENVI = in_folder + filename '.dat' 
in_raster = raster(in_ENVI) 
index = 0 

# get raster information specific to each band 
desc = arcpy.Describe(in_raster) 

################### THIS IS WHERE I GET THE ERROR ################## 
Runtime error 
Traceback (most recent call last): 
    File "<string>", line 23, in <module> 
NameError: name 'raster' is not defined 
################### SCRIPT TERMINATED ############################## 

for band in desc.children: 
    print band 
    bandName = band.name 
    band_path = os.path.join(in_raster, bandName) 
    dest_path = os.path.join(out_folder, filename '_' + band_names(index) + '.tif') 
    arcpy.CopyRaster_management(band_path, dest_path, "", "", "", "NONE", "NONE", "") 
    index = index + 1 

回答

0

好了,所以我其實想通了自己。這是我使用的代碼。該錯誤實際上不在arcpy.Describe()中,而是在arcpy.CopyRaster_management中,因爲我沒有將band_name [index]轉換爲字符串。

dest_path = os.path.join(out_folder, filename + str(band_names[index]) + '.tif')