ArcPy 批量给shp字段赋值

工作中需要做大量图层的拼接,为了在拼接完成后还能知道原始数据文件是什么,所以写了个Python脚本对每个图层的SOURCE字段进行赋值。

附上Python代码:

 1 # -*- coding: utf-8 -*-
 2 # nightroad
 3 import sys
 4 import arcpy
 5 
 6 path = "C:/Users/nightroad/Desktop/SHP"
 7 arcpy.env.workspace = path
 8 ff = arcpy.ListFeatureClasses()
 9 for fc in ff:
10     print(fc.replace(".shp", ""))
11     arcpy.CalculateField_management(fc,"SOURCE",'"'+fc.replace(".shp", "")+'"',"PYTHON_9.3")
12     print('Success:'+fc)
原文地址:https://www.cnblogs.com/nightroad/p/9366401.html