以下代码显示了我必须将输出文件夹声明为全局的第一步,以便以后的输出也可以保存在其中。现在我在输出文件夹字符串 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()