Python脚本裁切数据库

来源:互联网 发布:ice框架 java 编辑:程序博客网 时间:2024/04/28 09:55

以前使用了GP工具来遍历数据库中的要素层,实现裁切。 

现在尝试用Python,实现起来也比较方便,速度比写一个小的应用程序快得多

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#重载sys,设置编码
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
#添加引用
import arcpy
import string
  
try:
    db = arcpy.GetParameterAsText(0) #裁剪数据库
    clip_feat = arcpy.GetParameterAsText(1) #裁剪要素类
    outworkspace = arcpy.GetParameterAsText(2) #输出数据库
  
        #获取要素列表
        arcpy.env.workspace=db
        fcs = arcpy.ListFeatureClasses()
  
    for fc in fcs:
        arcpy.Clip_analysis(fc,clip_feat,outworkspace+"\\"+str(fc))
  
except arcpy.ExecuteError:
    print arcpy.GetMessages()

把它导入ToolBox中(导入方法:ArcGIS使用Python脚本工具),效果如下:

0 0
原创粉丝点击