gis里将当前mxd下的所有图层的名称写入其shape的属性表
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Users\Administrator\Desktop\5-171.mxd") #需要修改的mxd的路径
df = arcpy.mapping.ListDataFrames(mxd, "")[0] #该mxd下面第一个数据框
lyr = arcpy.mapping.ListLayers(mxd, "", df) #该数据框下所有的图层
for ly in lyr:
name=ly.name #读取图层的名字
try:
arcpy.AddField_management(ly, "test", "TEXT", "", "", "20") #执行添加test的字段
fieldName = "test"
expression = "'"+name+"'"
arcpy.CalculateField_management(ly, fieldName, expression, "PYTHON_9.3") #将名字写入test字段
except Exception,e:
print e
对于有用的人可能有用吧!-.-方便批量录入信息吧
转载自:https://blog.csdn.net/qq_36808376/article/details/80981470