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

Thursday, May 22, 2025

๐Ÿ” 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 file for output.

๐Ÿ” Dataset & Feature Class Loop

It loops through all feature datasets and standalone feature classes, capturing relevant metadata about each field.

๐Ÿง  Filtering Logic

Only fields that meet the following criteria are exported:

  • Their name contains "type" (case-insensitive)

  • They are of type "Integer" (which is ArcPy's internal label for Long)

  • They do not have a domain assigned

๐Ÿ“ CSV Output

Matching fields are written into a structured CSV file, showing:

  • GDB name

  • Dataset name

  • Feature class

  • Field name

  • Field type


๐Ÿงพ The Code

python
import arcpy import csv # === INPUTS === gdb_path = r"C:\Work\Projects\MPDA\DataModel\Schema\Buildings.gdb" output_csv = r"C:\Work\Projects\MPDA\DataModel\Schema\Buildings_Fields.csv" # === SETUP CSV === headers = ['GDBName', 'Feature dataset', 'Feature class', 'Field', 'Datatype'] with open(output_csv, 'w', newline='', encoding='utf-8') as csvfile: writer = csv.writer(csvfile) writer.writerow(headers) gdb_name = arcpy.Describe(gdb_path).baseName arcpy.env.workspace = gdb_path datasets = arcpy.ListDatasets(feature_type='feature') or [''] # Includes standalone FCs for dataset in datasets: feature_classes = arcpy.ListFeatureClasses(feature_dataset=dataset) for feature_class in feature_classes: fc_path = f"{gdb_path}\\{dataset}\\{feature_class}" if dataset else f"{gdb_path}\\{feature_class}" fields = arcpy.ListFields(fc_path) for field in fields: if ( "type" in field.name.lower() and field.type == "Integer" and not field.domain ): writer.writerow([gdb_name, dataset or "Standalone", feature_class, field.name, field.type]) print(f"✅ CSV file created successfully at: {output_csv}")

๐Ÿ”Ž Use Cases

  • ๐Ÿ” Auditing field structure across a GDB

  • ๐Ÿ› ️ Schema cleanup: identifying unstandardized or unused fields

  • ๐Ÿ“ค Exporting metadata for documentation or review

  • ๐Ÿšซ Detecting missing domains on critical integer fields


✅ Benefits

  • Automates what would be a tedious manual inspection

  • Works for both dataset-bound and standalone feature classes

  • Helps track down inconsistencies in schema structure

  • Outputs a clean CSV for further use in Excel or other tools

No comments:

Post a Comment