Hello everyone,
How can I match fields that have a different names, for example the same field is called ProjNum in one FC and ProjectNumber in another.
currently I am using this source code to append one FC or Table to another.
fieldmappings = arcpy.FieldMappings()
#Like when you manually choose a layer in the toolbox and it adds the fields to grid
if arcpy.Exists (CurrentFeatureOutput):
fieldmappings.addTable( CurrentFeatureOutput)
fieldmappings.addTable(CurrentFeatureInput )
arcpy.Append_management( CurrentFeatureInput , CurrentFeatureOutput , "NO_TEST", fieldmappings)
Hi @JoseSanchez ,
The link below provides an example that shows how to map fields with different names:
Thank you MehdiPira1
I am going to reuse the function posted as sample, it is exactly what I need
@MehdiPira1 wrote:Hi @JoseSanchez ,
The link below provides an example that shows how to map fields with different names:
def fieldMapping(fc_in,fc_out):
try:
# value in the 'in' feature class, value in the feature class to be appended to
dico = {'Assessed_Value': 'ARN', 'Total_Value': 'TotalValue'}fieldmappings = arcpy.FieldMappings()
fieldmappings.addTable(fc_in)
fieldmappings.addTable(fc_out)for input,output in dico.items():
field_to_map_index = fieldmappings.findFieldMapIndex(output)
field_to_map = fieldmappings.getFieldMap(field_to_map_index)
field_to_map.addInputField(fc_in,input)
fieldmappings.replaceFieldMap(field_to_map_index, field_to_map)return fieldmappings
except:
logging.exception('Generic error raised during fieldmap creation')
raise
Glad to hear that, @JoseSanchez .
Please mark as helpful if you find it helpful. If it answered your question please mark it as answered.
Thanks