下面的代码展示了第一步,我必须将output文件夹声明为global,这样以后的输出也可以保存在其中。现在我在输出文件夹字符串r'optfile/ras1'处得到一个错误。如果您能帮助您正确地将文件存储在输出文件夹中并将其声明为全局文件,将不胜感激。在
import arcpy
import os
import pythonaddins
from datetime import datetime
now = datetime.now()
month = now.month
year = now.year
optfile = "C:/temp/"+str(year)+"_"+str(month)
class DrawRectangle(object):
"""Implementation for rectangle_addin.tool (Tool)"""
def __init__(self):
self.enabled = True
self.cursor = 1
self.shape = 'Rectangle'
os.makedirs(optfile)
def onRectangle(self, rectangle_geometry):
"""Occurs when the rectangle is drawn and the mouse button is released.
The rectangle is a extent object."""
extent = rectangle_geometry
arcpy.Clip_management(r'D:/test', "%f %f %f %f" %(extent.XMin, extent.YMin, extent.XMax, extent.YMax), r'optfile/ras1', "#", "#", "NONE")
arcpy.RefreshActiveView()
我认为你的意思是值
r'optfile/ras1'
没有使用你的optfile
变量。这是因为Python不会神奇地读懂你的思想,也不会替换恰好与变量名匹配的部分字符串。在您必须显式地使用
optfile
变量,方法是将它与/ras1
部分串联起来:或者,更好的方法是使用
^{pr2}$os.path.join()
函数为您处理路径分隔符:请注意,您的问题与全局变量无关;这适用于您想要连接的变量来自何处。在
相关问题 更多 >
编程相关推荐