Is there a way to use Python/arcpy to access/list a feature class's alias? I'm talking about the name of the feature class, not field aliases (which I already figured out how to do).
Based on my searching of Esri's documentation, there doesn't seem to be a way to do this via Describe or ListFeatureClasses. Is there some other way?
I ask because I'm trying to create a CSV file that contains many feature classes' names, fields, and field aliases. I will use the file to review the field names and stuff and write notes about things I want to change when I migrate the data from a file geodatabase to an enterprise geodatabase. It would also be helpful to be able to see the feature class alias in this CSV file.
Thanks in advance for any help!
Solved! Go to Solution.
import arcpy
fc1 = r"C:\arcpro_npg\Project_npg\TestShapes.gdb\clp"
desc = arcpy.da.Describe(fc1)
dir(desc)
#-- snip ---
# big list of properties
# alternately
desc.keys()
Out[7]: dict_keys(['catalogPath', 'FIDSet', 'size', 'dateCreated',
'dateAccessed', 'dateModified', 'workspace', 'supportsBigObjectID',
'supportsBigInteger', 'supportsTimeOnly', 'supportsDateOnly',
'supportsTimestampOffset', 'aliasName', 'areaFieldName', 'attributeRules',
'baseName', 'canVersion', 'changeTracked', 'children', 'childrenExpanded',
'createdAtFieldName', 'creatorFieldName', 'dataElementType', 'datasetType',
'dataType', 'defaultSubtypeCode', 'DSID', 'editedAtFieldName',
'editorFieldName', 'editorTrackingEnabled', 'extension',
'extensionProperties', 'extent', 'featureType', 'fields', 'file',
'fullPropsRetrieved', 'geometryStorage', 'globalIDFieldName', 'hasGlobalID',
'hasM', 'hasOID', 'hasOID64', 'hasSpatialIndex', 'hasZ', 'indexes',
'isCOGOEnabled', 'isCompressed', 'isTimeInUTC', 'isVersioned',
'lengthFieldName', 'metadataRetrieved', 'MExtent', 'modelName', 'name',
'OIDFieldName', 'path', 'rasterFieldName', 'relationshipClassNames',
'representations', 'shapeFieldName', 'shapeType', 'spatialReference',
'subtypeFieldName', 'versionedView', 'ZExtent'])
# ----
desc['aliasName']
''
# == my fc doesn't have an alias set
Give it try with your data
import arcpy
fc1 = r"C:\arcpro_npg\Project_npg\TestShapes.gdb\clp"
desc = arcpy.da.Describe(fc1)
dir(desc)
#-- snip ---
# big list of properties
# alternately
desc.keys()
Out[7]: dict_keys(['catalogPath', 'FIDSet', 'size', 'dateCreated',
'dateAccessed', 'dateModified', 'workspace', 'supportsBigObjectID',
'supportsBigInteger', 'supportsTimeOnly', 'supportsDateOnly',
'supportsTimestampOffset', 'aliasName', 'areaFieldName', 'attributeRules',
'baseName', 'canVersion', 'changeTracked', 'children', 'childrenExpanded',
'createdAtFieldName', 'creatorFieldName', 'dataElementType', 'datasetType',
'dataType', 'defaultSubtypeCode', 'DSID', 'editedAtFieldName',
'editorFieldName', 'editorTrackingEnabled', 'extension',
'extensionProperties', 'extent', 'featureType', 'fields', 'file',
'fullPropsRetrieved', 'geometryStorage', 'globalIDFieldName', 'hasGlobalID',
'hasM', 'hasOID', 'hasOID64', 'hasSpatialIndex', 'hasZ', 'indexes',
'isCOGOEnabled', 'isCompressed', 'isTimeInUTC', 'isVersioned',
'lengthFieldName', 'metadataRetrieved', 'MExtent', 'modelName', 'name',
'OIDFieldName', 'path', 'rasterFieldName', 'relationshipClassNames',
'representations', 'shapeFieldName', 'shapeType', 'spatialReference',
'subtypeFieldName', 'versionedView', 'ZExtent'])
# ----
desc['aliasName']
''
# == my fc doesn't have an alias set
Give it try with your data
Thank you, Dan! The Describe documentation for feature classes only listed 8 properties for feature classes - so, only a small portion of the ones you accessed. And it hadn't "clicked" for me that arcpy.da.Describe produces a dictionary and that the dictionary could be explored like that.
For anyone else who may be wondering about this, here is how I got the feature class's alias into a variable:
import arcpy
arcpy.env.workspace = "\\\\my\\file\\geodatabase"
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
desc = arcpy.da.Describe(fc)
alias = desc['aliasName']
# Then print alias or put it in a list of things to write to a csv.
For a geodatabase table or feature class, "aliasName" is an inherited from Geodatabase Table properties - ArcGIS Pro | Documentation
Just a warning, the da.Describe can get really expensive. Describing a geo database takes a few milliseconds with regular Describe, and everything else is lazy loaded as you access it, but da.Describe will parse the whole tree and can take seconds sometimes.
Alternate Perspective:
Of course "seconds" would probably be important in emergency uses of GIS 😁
For others it provides a welcome respite from an otherwise harrowing day.
Absolutely agree, there have been tons of times that I've bitten the bullet and allowed operations to drag on because the alternative is spending a day or two doing that same thing by hand.
I just remember the first time I discovered da.Describe and foolishly re-wrote several processes to use it because it saved me a ton of boilerplate only to be shocked that those processes were now taking 10x as long and my co-workers were understandably upset!