πŸ” 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 ...

Wednesday, April 30, 2025

πŸ“ Bulk Update Field Aliases in All Feature Classes (ArcPy + CSV)

 

πŸ“ Bulk Update Field Aliases in All Feature Classes (ArcPy + CSV)

Keeping your GIS field names meaningful is important—but sometimes they can be cryptic due to system constraints (e.g., LU_CODE, ADM_NAME). That’s where aliases come in: they provide readable labels without changing the field's actual name.

Here’s a simple ArcPy script that updates field aliases across all feature classes—including those inside datasets—using a CSV file.


🧾 Input: CSV Format

Make sure your CSV looks like this:

csv
FieldName,AliasName LU_CODE,Land Use Code ADM_NAME,Administrative Name CITY_ID,City Identifier

This approach is great for global alias updates when you know the field names but don’t want to repeat entries for every feature class.


πŸ’» Python Script (ArcPy)

python
import arcpy import csv import os # === INPUT PARAMETERS === gdb_path = r"C:\Users\Testuser\OneDrive - GPC Global Information Solutions LLC\Projects\MPDA\Data\MPDA_MigratedData_25_03\MPDA_MigratedData_1.gdb" csv_path = r"C:\Users\Testuser\Downloads\Updated_Alias_Names.csv" # === LOAD CSV TO DICTIONARY === field_alias_dict = {} with open(csv_path, newline='', encoding='utf-8') as csvfile: reader = csv.DictReader(csvfile) for row in reader: field_name = row['FieldName'].strip() alias_name = row['AliasName'].strip() field_alias_dict[field_name] = alias_name # === PROCESS FEATURE CLASSES IN DATASETS === arcpy.env.workspace = gdb_path datasets = arcpy.ListDatasets(feature_type='feature') or [] # Include root-level feature classes datasets.append("") for ds in datasets: feature_classes = arcpy.ListFeatureClasses(feature_dataset=ds) for fc in feature_classes: fc_path = os.path.join(gdb_path, ds, fc) if ds else os.path.join(gdb_path, fc) print(f"πŸ”„ Processing: {fc_path}") fields = arcpy.ListFields(fc_path) for field in fields: if field.name in field_alias_dict: new_alias = field_alias_dict[field.name] try: print(f" ➤ Updating alias for '{field.name}' to '{new_alias}'") arcpy.AlterField_management( in_table=fc_path, field=field.name, new_field_alias=new_alias ) except Exception as e: print(f" ⚠️ Failed to update field '{field.name}': {e}") print("\n✅ Alias name update completed.")

πŸ”§ Use Cases

  • Renaming confusing or auto-generated field names in bulk

  • Preparing datasets for external sharing (with readable labels)

  • Standardizing field aliases across hundreds of layers

No comments:

Post a Comment