我有一个相当简单的调用几个函数的python循环,并将输出写入文件。为此,创建一个文件夹,并将文件保存在该文件夹中。当重新运行程序时出现问题
当我第一次使用唯一文件名运行程序时,它运行良好。但是,如果我尝试再次运行它,它将无法工作,我不明白为什么。我很确定这不是覆盖文件的问题,因为我在重新运行之前删除了该文件夹,并且这是文件存储的唯一位置。有没有一个概念让我误解?
有问题的文件是'buff1.shp'。我正在使用Python 2.5在ArcGIS中运行一些分析
感谢您的任何建议(包括有关如何改进我的编码风格的建议)。还有一点需要注意的是,目前我的循环只使用一个值,因为我正在测试这个值。
# Import system modules
import sys, string, os, arcgisscripting, shutil
# Create the Geoprocessor object
gp = arcgisscripting.create()
# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Spatial Statistics Tools.tbx")
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")
# specify workspace
gp.Workspace = "C:/LEED/Cities_20_Oct/services"
path = "C:\\LEED\\Cities_20_Oct\\services\\"
results = 'results\\'
os.mkdir(path + results)
newpath = path + results
# Loop through each file (0 -> 20)
for j in range(0,1):
in_file = "ser" + str(j) + ".shp"
in_file_2 = "ser" + str(j) + "_c.shp"
print "Analyzing " + str(in_file) + " and " + str(in_file_2)
#Loop through a range of buffers - in this case, 1,2
for i in range(1,2):
print "Buffering....."
# Local variables...
center_services = in_file_2
buffer_shp = newpath + "buff" + str(i) + ".shp"
points = in_file_2
buffered_analysis_count_shp = newpath + "buffered_analysis_count.shp"
count_txt = newpath + "count.txt"
# Buffer size
b_size = 1000 + 1000 * i
b_size_input = str(b_size) + ' METERS'
print "Buffer:" + b_size_input + "\n"
# Process: Buffer...
gp.Buffer_analysis(center_services, buffer_shp, b_size_input, "FULL", "ROUND", "ALL", "")
print "over"
(要弄清这个问题,我编辑的几个部分未无代码的其余部分是有意义的错误仍然在程序中。)
错误消息:
ExecuteError: ERROR 000210: Cannot create output C:\LEED\Cities_20_Oct\services\results\buff1.shp Failed to execute (Buffer).
“它不会工作”是什么意思? –
而不是评论,请编辑您的原始问题。 –