• 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!")
  • 相关阅读:
    DataSet生成gb2312编码的xml
    利用SendMessage实现C#进程间通信
    DataSet与Xml之间的转换
    xml解析
    当前时间加指定的几个月
    Excel利用poi导入导出(上)
    mybatis.generator.plugins生成基础类
    Excel利用poi导入导出(下)
    ASP.NET 中的Session统一管理
    太幸福了,没有比我们更开放的网络了!
  • 原文地址:https://www.cnblogs.com/nightroad/p/9371222.html
Copyright © 2020-2023  润新知