๐Ÿ” Extract Field Names Containing 'type' (Integer Fields Without Domain) from GDB Using ArcPy

  ⚙️ How the Script Works ๐Ÿ—‚️ Geodatabase Setup The script starts by pointing to a target File Geodatabase (.gdb) and initializing a CSV ...

Tuesday, April 29, 2025

✏️ Bulk Update Field Aliases in a Geodatabase Using ArcPy and CSV

 

✏️ Bulk Update Field Aliases in a Geodatabase Using ArcPy and CSV

Maintaining clear and readable aliases for fields in your GIS layers is vital for both data clarity and user experience. Whether you’re preparing datasets for a client, public release, or internal documentation, consistent aliases make a big difference.

Here’s a handy Python script using ArcPy that lets you batch-update field aliases using a CSV file—no more clicking through each field in ArcGIS Pro!


๐Ÿงพ What the Script Does

  • Reads a CSV file containing:

    • Dataset name (optional)

    • Feature class name

    • Field name

    • New alias

  • Locates the feature class in the specified .gdb

  • Applies the new alias using AlterField_management


๐Ÿ“ฆ Folder Setup

Your project folder might look like this:

objectivec
MPDA_MigratedData_25_03/ │ ├── MPDA_MigratedData.gdb/ │ └── (your feature classes & datasets) │ └── BackUP/ └── AliasNamesToUpdate.csv

๐Ÿ“„ Sample CSV Structure

csv
DatasetName,FeatureClassName,FieldName,AliasName ,CityBoundaries,City_ID,City Identifier LandUse,Parcels,LU_CODE,Land Use Code Admin,Regions,ADM_NAME,Administrative Name

If the feature class is at the root level of the GDB (not inside a dataset), leave DatasetName blank.


๐Ÿ’ป Python Script (ArcPy)

python
import arcpy import csv import os import codecs # === INPUTS === gdb_path = r"C:\Path\To\Your.gdb" csv_path = r"C:\Path\To\AliasNamesToUpdate.csv" # Read CSV with UTF-8-SIG (handles BOM from Excel) with codecs.open(csv_path, 'r', encoding='utf-8-sig') as csvfile: reader = csv.DictReader(csvfile) reader.fieldnames = [col.strip() for col in reader.fieldnames] print("๐ŸŸข Headers:", reader.fieldnames) for row in reader: dataset_name = row['DatasetName'].strip() feature_class = row['FeatureClassName'].strip() field_name = row['FieldName'].strip() alias_name = row['AliasName'].strip() # Get full path to feature class full_fc_path = os.path.join(gdb_path, dataset_name, feature_class) if dataset_name else os.path.join(gdb_path, feature_class) if arcpy.Exists(full_fc_path): print(f"๐Ÿ”„ Processing: {full_fc_path} ➤ Field: {field_name}") try: arcpy.AlterField_management( in_table=full_fc_path, field=field_name, new_field_alias=alias_name ) print(f"✅ Updated alias to: {alias_name}") except Exception as e: print(f"⚠️ Failed to update alias for {field_name}: {e}") else: print(f"❌ Feature class not found: {full_fc_path}")

๐Ÿ”„ Why Use This?

  • Speeds up metadata cleanup

  • Enables non-GIS staff to manage aliases via Excel

  • Reduces manual errors

  • Keeps alias naming consistent across large datasets


๐Ÿง  Pro Tips

  • Test on a copy of your geodatabase first.

  • To also rename fields, use new_field_name= in the same function.

  • Works in ArcGIS Pro (Python 3) or ArcMap (Python 2)—but always use the version that matches your .gdb.