![](zzz/editor/img/code.gif)
# Import system modules
import sys, string, os
dir = 'H:\\NDVI\\ndvi'
# Import arcpy module
import arcpy
files = os.listdir(dir)
for f in files:
if os.path.splitext(f)[1] == '.tif':
# Script arguments...
Input_raster_file = dir + os.sep + f
# Local variables...
Output_Workspace = "H:\\NDVI\\ndvi\\ASCII"
# =============== file name process ======================
basename = os.path.splitext(f)[0];
Output_raster = Output_Workspace + os.sep + basename + ".txt";
if os.path.exists(Output_raster) == False:
print Input_raster_file
# Process: Raster To Other Format (multiple)...
arcpy.RasterToASCII_conversion(Input_raster_file,Output_raster)
print Output_raster
import sys, string, os
dir = 'H:\\NDVI\\ndvi'
# Import arcpy module
import arcpy
files = os.listdir(dir)
for f in files:
if os.path.splitext(f)[1] == '.tif':
# Script arguments...
Input_raster_file = dir + os.sep + f
# Local variables...
Output_Workspace = "H:\\NDVI\\ndvi\\ASCII"
# =============== file name process ======================
basename = os.path.splitext(f)[0];
Output_raster = Output_Workspace + os.sep + basename + ".txt";
if os.path.exists(Output_raster) == False:
print Input_raster_file
# Process: Raster To Other Format (multiple)...
arcpy.RasterToASCII_conversion(Input_raster_file,Output_raster)
print Output_raster
输入文件名是这样的 heihe_2001_NDVI_recon.001.tif
heihe_2001_NDVI_recon.002.tif
heihe_2001_NDVI_recon.003.tif
....
问题如下:1.if os.path.splitext(f)[1] == '.tif': 是什么意思
2.basename = os.path.splitext(f)[0]; 中的[0]是什么意思
3.运行报错 File "<string>", line 17, in <module>
NameError: name 'Input_raster_file' is not defined 问题出在哪
求各位大神解答,在此先谢过
[此贴子已经被作者于2017-6-27 19:06编辑过]