I would like to populate the alias names for the fields in the ACS 2014 5 year estimates file geodatabase (all 11439 of them). The ACS fgdb comes with the short_name and long_name in the metadata table. I have exported this into an excel spreadsheet, and think this would be best done using arcpy.AlterField_management() with openpyxl.
1 Answer 1
To simplify matters, I'll assume your excel spreadsheet is really a csv file with no headers and is formed like: field_name,alias
:
import arcpy, csv
csvfile = "<path to file>"
FC = "<path to feature class>"
#List of tuples
name_alias = [rows for rows in csv.reader(open(csvfile))]
errors = []
for name,alias in name_alias:
try:
print("Altering.....{}".format(name))
arcpy.AlterField_management(FC, name, new_field_alias=alias)
except Exception as e:
errors.append(name) #Keep running list of field names that failed.
print(e)
pass
if errors: print errors
Improving this to support Excel files should be straightforward enough.
If for whatever reason failure occurs (missing field, schema lock, improper name, etc.), the error will be printed and processing continued.