๐Ÿ” 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, May 20, 2025

๐Ÿ”„ Copy Field Values Between Columns Across Multiple GDBs Using ArcPy

 

๐Ÿ”„ Copy Field Values Between Columns Across Multiple GDBs Using ArcPy

In many GIS workflows, especially in large-scale data preparation or standardization tasks, you might need to duplicate the value of one field into other fields—for example, copying a unique identifier or standardized code from one field into localized or secondary fields for display or downstream processing.

This ArcPy script simplifies that process by automatically copying values from a source field (PORTID) to one or more target fields (PORTNAMEEG, PORTNAMEAR) across all feature classes in multiple File Geodatabases (GDBs). It handles both standalone feature classes and those nested within datasets.


⚙️ How the Script Works

๐Ÿ—‚️ Folder Setup

You define the folder path containing all the GDBs you want to process. The script scans this folder and processes each GDB found within it.

๐Ÿ” Field Mapping

You specify:

  • A source field (e.g., PORTID)

  • One or more target fields (e.g., PORTNAMEEG, PORTNAMEAR)

The script copies the value from the source field into each target field using a simple Python 3 field calculator expression.

๐Ÿ” Traversing GDB Structure

The script:

  • Handles standalone feature classes

  • Handles feature classes inside datasets

  • Skips no steps—every feature class is checked and updated

๐Ÿง  Smart Execution

For each feature class, arcpy.CalculateField is used to copy the data, keeping things clean, fast, and scriptable.


๐Ÿงพ The Code

python
import arcpy import os # === USER INPUT === gdb_folder = r'C:\Path\To\Your\GDBs' source_field = "PORTID" target_fields = ["PORTNAMEEG", "PORTNAMEAR"] for folder in os.listdir(gdb_folder): if folder.endswith(".gdb"): gdb_path = os.path.join(gdb_folder, folder) arcpy.env.workspace = gdb_path # --- 1. Standalone Feature Classes --- feature_classes = arcpy.ListFeatureClasses() for fc in feature_classes: print(f"Working on standalone Feature Class: {fc}") for target_field in target_fields: expression = f'!{source_field}!' arcpy.management.CalculateField(fc, target_field, expression, "PYTHON3") print(f"✅ Updated {target_field} with values from {source_field} in {fc}") # --- 2. Feature Classes in Datasets --- datasets = arcpy.ListDatasets() or [] for ds in datasets: arcpy.env.workspace = os.path.join(gdb_path, ds) dataset_feature_classes = arcpy.ListFeatureClasses() for fc in dataset_feature_classes: print(f"Working on Feature Class: {fc} in Dataset: {ds}") for target_field in target_fields: expression = f'!{source_field}!' arcpy.management.CalculateField(fc, target_field, expression, "PYTHON3") print(f"✅ Updated {target_field} with values from {source_field} in {fc}") print("\n✅ Field update process completed.")

๐Ÿ”Ž Use Cases

  • ๐Ÿท️ Label localization: Copy a unique identifier into translated name fields for multilingual mapping.

  • ๐Ÿ› ️ Schema normalization: Standardize data values across fields before publishing or merging.

  • ๐Ÿงน Data cleanup: Replace blank or placeholder target fields with valid values from trusted fields.

  • ๐Ÿ“ฆ Bulk processing: Apply the same rule across dozens of geodatabases without manual editing.


✅ Key Benefits

  • Fully automated, no need for manual field edits

  • Works on both top-level and dataset-level feature classes

  • Uses Python 3 syntax, ensuring compatibility with ArcGIS Pro

  • Lightweight and fast—great for batch updates across large projects

No comments:

Post a Comment