import arcpy
# set workspace environment to your GDB
arcpy.env.workspace = r"C:\aka\117"
# list the feature classes
fcList = arcpy.ListFeatureClasses()
fieldName1 = "xCentroid"
fieldName2 = "yCentroid"
fieldPrecision = 18
fieldScale = 11
# loop through list
for fc in fcList:
print(fc.encode("gbk"))
Fields_lst = arcpy.ListFields(fc)
#check if field exists, if not, add it and calculate
if fieldName1 not in Fields_lst:
arcpy.AddField_management(fc,fieldName1,"DOUBLE")
arcpy.CalculateField_management(fc, fieldName1, "!SHAPE.CENTROID.X!","PYTHON_9.3")
if fieldName2 not in Fields_lst:
arcpy.AddField_management(fc,fieldName2,"DOUBLE")
arcpy.CalculateField_management(fc, fieldName2, "!SHAPE.CENTROID.X!","PYTHON_9.3")
没有评论:
发表评论