I am trying to use FieldMap in arcpy to merge only a few of the same fields from 8 feature classes. There are many different fields in all of the different feature classes, but I have identified the 9 fields I want in my final merged feature class. Instead of merging all the fields I identify it only chooses the first field in my list and I end up with a merged file with one field "COUNTY_F". What am I missing?
fClasses = [] i=0 fcs = arcpy.ListFeatureClasses() for fc in fcs: fClasses.append(fc) i = i+1 #Map Fields for Merge inFields= ["COUNTY_F", "UNIQUE_ID", "TAXPAYER", "PARCEL_ID", "CURRENTUSE_CODE", "CURRENTUSE_DESC", "PRESENTUSE_CODE", "PRESENTUSE_DESC", "ACRES_ASSES"] fm = arcpy.FieldMappings() fm_type = arcpy.FieldMap() for field in inFields: fm_type.addInputField( "Clallam_WorkingForest_2013", field) fm_type.addInputField( "GraysHarbor_WorkingForest_2013", field) fm_type.addInputField( "Jefferson_WorkingForest_2013", field) fm_type.addInputField( "King_WorkingForest_2013", field) fm_type.addInputField( "Kittitas_WorkingForest_2013", field) fm_type.addInputField( "Mason_WorkingForest_2013", field) fm_type.addInputField( "Pierce_WorkingForest_2013", field) fm_type.addInputField( "Snohomish_WorkingForest_2013", field) fm.addFieldMap(fm_type) arcpy.Merge_management(fClasses, "Merged", fm) print "Merge: SUCCESS."
If the fields in the featureclasses are all named the same, I guess you don't have to use field mapping... You could simply merge the featureclasses together and then remove any redundant fields...