Bootstrap

arcgis中用python脚本批量给多个要素类的相同字段赋值

1、python脚本

import arcpy

# 设置工作空间路径
arcpy.env.workspace = r"D:\test.gdb"

# 要素集名称
feature_dataset = "test"

# 线要素类名称列表,初始化为空
line_feature_classes = []

# 遍历要素集获取所有线要素类
for fc in arcpy.ListFeatureClasses(feature_dataset=feature_dataset):
    desc = arcpy.Describe(feature_dataset + "/" + fc)
    if desc.shapeType == "Polyline":
        line_feature_classes.append(fc)

# 字段名称列表
field_names = ["QCX_COORD", "QDY_COORD", "ZDX_COORD", "ZDY_COORD"]

# 开启编辑会话
edit = arcpy.da.Editor(arcpy.env.workspace)
edit.startEditing()

# 开启对每个线要素类的编辑操作并赋值
for fc in line_feature_classes:
    try:
        edit.startOperation()
        with arcpy.da.UpdateCur
;