Select to view content in your preferred language

field mapping in python for ArcGIS 10

11437
10
06-20-2011 08:49 AM
RuthEmerick
New Contributor II
Does anyone have or know of any field mapping code samples for arcpy? I'm using the Append tool, and read that there's a simpler way of doing a field map than creating a field map object. However, I've been unable to find any details or code samples.

Thanks!
Tags (2)
10 Replies
GlennKammerer
New Contributor II
Hey guys,

I was thinking about this very problem today.
I tried to create a simpler, cleaner interface for straightforward field mapping situations. Using Mathew's code and example as a reference, I came up with the following:

def GetFieldMappings(fc_in, fc_out, dico):
    field_mappings = arcpy.FieldMappings()
    field_mappings.addTable(fc_in)

    for input, output in dico.iteritems():
        field_map = arcpy.FieldMap()
        field_map.addInputField(fc_in, input)        
        field = fieldmap.outputField        
        field.name = output
        field_map.outputField = field
        field_mappings.addFieldMap(field_map)
        del field, field_map

    return field_mappings




Just curious, what is the fc_out argument for in the function? I don't see it used at all.
0 Kudos