I am trying to replace field names of a table stored in a file geodatabase using a dictionary as a lookup table. My field names got cut off from the Tabulate Area tool (Tabulate Area Truncates Field Names in ArcGIS Pro?). The following process works, however since I have about 2,000 fields, the process is taking over an hour (and counting) to run, which defeats the purpose of making an automated tool in my case.
Is there a way to run this process faster?
I'm essentially looking to take two fields from the attribute table of my raster, turn them into a dictionary (key: value is CLASS_TRUN: Class_Name) and then replace the Tabulate Area tool output table's field names (each a unique value from CLASS_TRUN) with it's corresponding dictionary value (Class_Name).
I'm using python 3.4 for ArcGIS Pro.
classDict = {}
with arcpy.da.UpdateCursor(in_table = supervised_tiff, field_names = ['Class_Name', 'CLASS_TRUN']) as cursor:
for row in cursor:
classDict[row[1]] = row[0]
TabulateArea(in_zone_data = bad_label_shapefile, zone_field = 'crop', in_class_data = supervised_tiff, class_field = 'Class_Name', out_table = bad_sig_table)
output_table_fields = [field.name for field in arcpy.ListFields(bad_sig_table)]
for i in output_table_fields:
if i in classDict.keys():
arcpy.AlterField_management(in_table = bad_sig_table, field = i, new_field_name = classDict[i], field_type = '', field_length = 64)
No comments:
Post a Comment