ArcGIS批量修改字段名称或类型
ArcPy就和ArcObjects,强大得令人发指,呵呵,开个玩笑!
在实际工作中会碰到这样的需求,shape file or geodatabase的feature class的字段名和字段类型不是我们想要的,可是通过ArcGIS的软件或者数据库本身都没法去修改它。怎么办,ArcPy可以显身手了。
import arcpy
from arcpy import env
# use your own
env.workspace = ""
# use your own
outpath = ""
fcList = arcpy.ListFeatureClasses()
for infc in fcList:
outfc = infc
print "in featureclass : " + infc + " out featureclass : " + outfc
fieldmappings = arcpy.FieldMappings()
infields = arcpy.ListFields(infc)
for infield in infields:
if infield.name == "OBJECTID" or infield.name == "shape" or infield.name == "Shape":
continue
fieldmap = arcpy.FieldMap()
fieldmap.addInputField(infc, infield.name)
outname = infield.name
outfield = fieldmap.outputField
outfield.name = outname.upper()
# if you want to change field type use :
# outfield.type = ""
fieldmap.outputField = outfield
fieldmappings.addFieldMap(fieldmap)
print "add field map " + infield.name + " - " + outfield.name
del fieldmap, outfield
print "start to copy ......"
arcpy.FeatureClassToFeatureClass_conversion(infc, outpath, outfc, "", fieldmappings)
print "done"
转载自:https://blog.csdn.net/heyubingzju/article/details/8825031