Select to view content in your preferred language

bulk setting alias names

5379
6
12-20-2010 02:36 PM
JohnGarvey
Deactivated User
I have some of the new ACS data in a file geodatabase and would like to bulk update the aliases of the fields.

ESRI documentation indicates that the field object has an alias property and is read/write.


When I set the alias it appears to work standard output python ide, but the changes are not registered in ArcCatalog.

Is there some way to commit changes or anything.
Tags (2)
0 Kudos
6 Replies
MatthewStarry
Occasional Contributor
Did you ever figure out how to set field aliases using Python?  I'm trying to do the exact same thing with ACS data.
0 Kudos
KevinMayall
Frequent Contributor
I'm having the same issue.  field.aliasName = value appears to work in python, but it does not seem to be committed to the geodb afterwards.
Kevin
0 Kudos
AdamInglis
Deactivated User
I'm also looking for a way to update the alias of 40 or FCs.
0 Kudos
JakeSkinner
Esri Esteemed Contributor
When calling list fields you essentially return a copy of the field in the form of the field object, so when modifying the field alias you are modifying the field object not the actually field in the database or layer.

There has been a bug logged to update the documentation stating this:

NIM068561:  Update the documentation for the fieldalias property and any other related properties that are listed as read and write. It should clarify that changing the property updates the field object only, it does not make an edit on the geodatabase.

One workaround, though probably not ideal, I found was using the 'Field Mapping' option in the Feature Class to Feature Class tool.  You can use this to update the field alias, then copy the new feature class replacing the old one.  Ex:

env.overwriteOutput = True

fc = "townships"

arcpy.FeatureClassToFeatureClass_conversion(fc, r"c:\temp\python\test.gdb", "Townships2", "",
                                            "NAME \"Township Name\" true true false 100 Text 0 0,First,#,C:\\temp\\python\\Test.gdb\\townships,NAME,-1,-1")
arcpy.Copy_management("townships2", "townships")

arcpy.Delete_management("townships2")
0 Kudos
KevinKozak
Regular Contributor
I was able to get the following python code to work so the alias names within the feature class are persistent in the geo-database.

Outline of process:
�?�  Create an arcpy fields mapping object and add the feature class fields using FieldMappings
�?�  Create a python list which has the field and alias name.
�?�  Export the arcpy fields mapping object to a text string using exportToString
�?�  Loop through the fields and alias names list and use the python string replace function to replace the field name with the alias name within the fields mapping exported string.
NOTE: the alias name is the doubled quoted word after the field name.

Python scripting:

v_fieldmappings = arcpy.FieldMappings()
v_fieldmappings.removeAll()
v_fieldmappings.addTable(v_input_fc)

v_field_alias_list = [['OBSID', 'Observation ID'], ['SPPCODE', 'Species Code'],
             ['COMNAME', 'Common Name'],  ['SCINAME', 'Scientific Name'],
             ['FEDSTAT', 'Federal Status Code'], ['FEDERAL_STATUS', 'Federal Status Desc'],
             ['STATESTAT', 'State Status Code'], ['STATE_STATUS', 'State Status Desc']]

v_fieldmappingsstring = str(v_fieldmappings.exportToString())
for v_field in v_field_alias_list:
             v_field_name = str(v_field[0])
             v_alias_field = str(v_field[1])
if v_fieldmappingsstring.find(v_field_name) >= 0:
                        v_fieldmappingsstring = v_fieldmappingsstring.replace('"' + v_field_name + '"', '"' + v_alias_field + '"')
else:
                       print "Field name " + v_field_name +"not found. Not setting alias name."

v_fieldmappings.loadFromString(v_fieldmappingsstring)

Then the v_fieldmappings can be used in a feature class to feature class process.
0 Kudos
DanielO_Donnell
Deactivated User
To be perfectly honest...

As frequently as we users need to modify aliases in bulk, ESRI should develop either...

1) a tool/script in the default/standard toolbox under Data Management/Fields,
2) a standard option within the "properties" dialog window for feature classes in ArcCatalog, and/or
3) the option to specify which row in a table contains aliases (i.e. during table_to_featureclass, etc.).**

...which enables users to modify / import a list of aliases in a batch process. This tool/option could/should function similar to importing of GDB domains & subtypes in ArcCatalog, and/or similar to joining feature classes w/ attribute tables in ArcMap.

** For example... if row 1 contains field names by default, then why can't row 2 contain the aliases, and rows 3 thru X contain the field values?
0 Kudos