Jesse,Yes, normally if fields with the same name contain the same data then dropping one of the fields is a great way to pair down the table size, but occaisonally input fields with the same name contain different data and both should be preserved.My solution (and my response) might be overly complicated but nevertheless I have included some code below that I used to account for this very issue. It's a bit clunky, I haven't yet switched to using dictionaries instead of multiple If statements but it works. Basically you loop over one of your layers and check the field names against those in the other layer that you want to join to (spatial or table join). Whenever you find field names that match, write them out to a python list. You can then use this list to add new fields to the layer who's attributes are getting attached during the join process. If you were wanting to preserve your point layer then you would add the new fields to your polygon layer, or if you want to preserve the polygon layer then you would add the new fields to your point layer. When you create the new fields you want to add something to the name to differentiate it from the original so it will be preserved in the output. For example if you have two fields both called "Name" and you want to preserve your polygon layer's geometry then leave the polygon's "Name" field alone but add a new field to your point layer called "Name_pt" and copy the point's "Name" attributes to the new "Name_pt" field. Basically you want to create a new name that shouldn't exist in either attribute table. You could get a little more ambitious and check the new name against both tables again but it probably isn't necessary if you pick some uncommon ending.The code is in four pieces and is part of a larger script that is designed to be used as a script tool: (Get the input parameters, Two functions, and one piece that checks if the user selected to preserve the input field names)Get input parameters:# Get User Input Parameters
Input_Table_Data = str(sys.argv[1])
Input_Table_Join_Field = str(sys.argv[2])
Input_GIS = str(sys.argv[3])
GIS_Join_Field = str(sys.argv[4])
Output_Location = str(sys.argv[5])
Output_Data_Name = str(sys.argv[6])
Keep_Type = str(sys.argv[7])
Keep_Matching = str(sys.argv[8])
Function 1: (Build a list of duplicate field names)def dup_field_name_list(fc_path, table_path): # For every field in the Input_GIS_Dataset, loop through the Input_Table and write out the matching table fields to a list
GIS_fieldlist = arcpy.ListFields(fc_path)
Table_fieldlist = arcpy.ListFields(table_path)
Plist = list()
for field in GIS_fieldlist:
GIS_field_name = str(field.name)
GIS_field_name_upper = GIS_field_name.upper()
for field in Table_fieldlist:
Table_field_name = str(field.name)
Table_field_name_upper = Table_field_name.upper()
if Table_field_name_upper == GIS_field_name_upper:
Plist.append(Table_field_name)
return Plist
Function 2: (Add new fields and copy the data, in this case it also deletes the original field)def rename_field(fc_path, dup_item):
field = dup_item
field_name_tab = field + "_tab"
field_name_tab_len = len(field_name_tab)
if field_name_tab_len > 10:
field_name_tab = field_name_tab[:6]
field_name_tab = field_name_tab + "_tab"
fieldlist = arcpy.ListFields(fc_path)
for field in fieldlist:
field_name = str(field.name)
field_type = str(field.type)
field_length = str(field.length)
if (field_name == dup_item):
# Case handling; Returned type of "String" uses the type of "text" and also uses length as an AddField parameter.
if (field_type == "String"):
field_type = "TEXT"
messages("Adding field: " + field_name_tab + ". The field type is: " + field_type + " and The length is: " + field_length)
arcpy.AddField_management(fc_path, field_name_tab, field_type, "", "", field_length, "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(fc_path, field_name_tab, "[" + field_name + "]")
if not field_name_tab.endswith("_tab"):
messages("Deleting: " + field_name)
arcpy.DeleteField_management(fc_path, field_name)
else:
# Case handling; Returned type of "Integer" converted to a type of "long" for use as AddField parameter.
if (field_type == "Integer"):
field_type = "LONG"
messages("Adding field: " + field_name_tab + ". The field type is: " + field_type + " and The length is: " + field_length)
arcpy.AddField_management(fc_path, field_name_tab, field_type, "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(fc_path, field_name_tab, "[" + field_name + "]")
if not field_name_tab.endswith("_tab"):
messages("Deleting: " + field_name)
arcpy.DeleteField_management(fc_path, field_name)
# Case handling; Returned type of "SmallInteger" converted to a type of "short" for use as AddField parameter.
elif (field_type == "SmallInteger"):
field_type = "SHORT"
messages("Adding field: " + field_name_tab + ". The field type is: " + field_type + " and The length is: " + field_length)
arcpy.AddField_management(fc_path, field_name_tab, field_type, "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(fc_path, field_name_tab, "[" + field_name + "]")
if not field_name_tab.endswith("_tab"):
messages("Deleting: " + field_name)
arcpy.DeleteField_management(fc_path, field_name)
# Case handling; Returned type of "Single" converted to a type of "Float" for use as AddField parameter.
elif (field_type == "Single"):
field_type = "FLOAT"
messages("Adding field: " + field_name_tab + ". The field type is: " + field_type + " and The length is: " + field_length)
arcpy.AddField_management(fc_path, field_name_tab, field_type, "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(fc_path, field_name_tab, "[" + field_name + "]")
if not field_name_tab.endswith("_tab"):
messages("Deleting: " + field_name)
arcpy.DeleteField_management(fc_path, field_name)
# Case handling; Returned type other than "String", "Integer", "SmallInteger", or "Single" handled normally.
else:
messages("Adding field: " + field_name_tab + ". The field type is: " + field_type + " and The length is: " + field_length)
arcpy.AddField_management(fc_path, field_name_tab, field_type, "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management(fc_path, field_name_tab, "[" + field_name + "]")
if not field_name_tab.endswith("_tab"):
messages("Deleting: " + field_name)
arcpy.DeleteField_management(fc_path, field_name)
# Reset variables
field_type = ""
field_length = ""
field_name = ""
field_name_tab = ""
dup_item = ""
Check Code: ####################################################################################################
#Call Rename Field function if the user wants to preserve matching fields in the output GIS dataset#
####################################################################################################
if Keep_Matching == "YES":
# Call function that detects duplicate field names between Input_GIS_Dataset and Input_Table, output a list of duplicates
duplicate_item_list = dup_field_name_list(Input_GIS_Dataset, Input_Table)
# Loop through list of duplicates to preserve duplicate items in the output dataset
for item in duplicate_item_list:
messages("Duplicate field name detected: " + item)
messages("Retaining Original Input Fields...")
rename_field(Input_Table, item) # Call rename field function
I hope this at least gives you some ideas.Joel