ArcPy 重命名拷贝删除图层

Posted nightroad

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ArcPy 重命名拷贝删除图层相关的知识,希望对你有一定的参考价值。

使用Python脚本进行图层的重命名拷贝及删除,并在过程中利用logging进行日志记录。

附上Python代码:

 1 # -*- coding: utf-8 -*-
 2 # nightroad
 3 import sys
 4 import arcpy
 5 import logging
 6 
 7 logging.basicConfig(level=logging.DEBUG,
 8                 format=%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s,
 9                 datefmt=%a, %d %b %Y %H:%M:%S,
10                 filename=log.txt,
11                 filemode=a)         
12 path = r"C:Users
ightroadAppDataRoamingESRIDesktop10.0ArcCatalog	est.sdeTEST"
13 arcpy.env.workspace = path
14 try:
15         print "delete line_1"
16         logging.info("delete line_1")
17         arcpy.Delete_management("line_1")
18         print "delete point_1"
19         logging.info("delete point_1")
20         arcpy.Delete_management("point_1")
21 except Exception as e:
22         print("no data or delete error!",e)
23         logging.warning("no data or delete error!")
24 try:
25         print "rename line"
26         logging.info("rename line")
27         arcpy.Rename_management("line", "line_1")
28         print "rename point"
29         logging.info("rename point")
30         arcpy.Rename_management("point", "point_1")
31         try:
32                 print "copy point"
33                 logging.info("copy point")
34                 arcpy.Copy_management(r"E:TEST.gdbTESTpoint","point")
35                 print "copy line"
36                 logging.info("copy line")
37                 arcpy.Copy_management(r"E:TEST.gdbTESTline","line")
38                 try:
39                         print "delete line_1"
40                         logging.info("delete line_1")
41                         arcpy.Delete_management("line_1")
42                         print "delete point_1"
43                         logging.info("delete point_1")
44                         arcpy.Delete_management("point_1")
45                 except Exception as e:
46                         print("delete error!",e)
47                         logging.error("delete error!")
48         except Exception as e:
49                 print("copy error!",e)
50                 logging.error("copy error!")
51 except Exception as e:
52         print("rename error!",e)
53         logging.error("rename error!")

 

以上是关于ArcPy 重命名拷贝删除图层的主要内容,如果未能解决你的问题,请参考以下文章

创建和删除和拷贝和移动重命名

ArcPy 创建图层空间索引

arcpy图层相关操作

Android 关于文件及文件夹的创建 删除重命名复制拷贝

arcpy实例教程-地图图层导出到要素类

arcpy.mapping常用四大件-Layer