该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
下面是一段python代码,要如何才能在Arctoolbox中实现呢?
#-*- encoding:UTF-8 -*-
#!/usr/bin/env python
# Author: 谢长波
# Purpose: 按字段分割要素类
# Created: 2012/10/9
import sys
import arcpy
import string
try:
inFC = arcpy.GetParameterAsText(0)
field = arcpy.GetParameterAsText(1)
folder = arcpy.GetParameterAsText(2)
#新建一个字符型字段做SQL查询条件判断字段
arcpy.management.AddField(inFC,"tmp","TEXT","","",50)
#用字典的key来获取条件字段的唯一值并将分割字段转为字符型
dict = {}
rows = arcpy.UpdateCursor(inFC)
for row in rows:
dict.setdefault(row.getValue(field),0)
row.tmp = str(row.getValue(field))
rows.updateRow(row)
del rows,row
#遍历分割字段唯一值列表,提取输出shp
for value in dict.keys():
SQL_statement = "tmp" + "='" + str(value)+ "'"
path = folder + "\\" + str(value) + ".shp"
arcpy.analysis.Select(inFC, path, SQL_statement)
#删除临时字段
arcpy.management.DeleteField(inFC,"tmp")
except arcpy.ExecuteError:
print arcpy.GetMessages()