【Arcpy】批量合并要素

批量合并要素

python2 中文问题
创建表
对表添加字段,计算表

# coding=utf-8
import arcpy
from arcpy import env
#设置中文
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
#更新许可
arcpy.CheckOutExtension('Spatial')
data_path="D:\个人资料\兼职\\8月\\6,合并图层\数据\\"
#可以覆盖已有要素
env.overwriteOutput = True
arcpy.env.workspace = data_path
#创建一个新要素
tables = arcpy.ListFeatureClasses()
arcpy.CreateFeatureclass_management(data_path+"out\\", "allroads.shp", "POLYLINE", tables[0])
#循环读取每个要素,更新字段,合并要素
for table in tables:
    name=table.split('.')[0]
    arcpy.AddField_management(table, "NAME", "TEXT")
    arcpy.CalculateField_management(table, "NAME", "'" + name + "'", "PYTHON_9.3")
    arcpy.Append_management(table, data_path+"out\\allroads.shp")
    print(name)

#arcpy.Merge_management(["Zemuhe Fault1.shp", "Yunwushan Fault.shp"], "allroads")

你可能感兴趣的:(Arcpy,python)