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

Count Features in All Feature Classes Across Multiple GDBs (ArcPy)

 

๐Ÿ“Š Count Features in All Feature Classes Across Multiple GDBs (ArcPy)

In geospatial data management, it is often necessary to get a quick overview of the number of features across various layers and geodatabases. This ArcPy script automates the process of counting features in each feature class—both within and outside feature datasets—across multiple File Geodatabases (GDBs).

This solution is especially helpful for large-scale GIS projects where understanding the data volume is essential for quality control, reporting, and performance tuning.


๐Ÿ” How the Script Works

๐Ÿ—‚ Directory Setup

The script begins by pointing to a parent folder that contains one or more .gdb files. It will recursively scan all subdirectories to find geodatabases.

๐Ÿ“‹ CSV Output

It outputs the results into a CSV file, listing each feature class’s name, the dataset it belongs to (if any), its shape type (Point, Polyline, Polygon, etc.), and the feature count.

๐Ÿ” GDB Iteration

It checks each folder for .gdb extensions and sets the ArcPy workspace to the current geodatabase being processed.

๐Ÿงพ Feature Class & Dataset Traversal

The script counts features in:

  • Standalone feature classes

  • Feature classes inside feature datasets

✅ Summary in CSV

For each feature class found, it logs:

  • GDB Path

  • GDB Name

  • Dataset Name (or None)

  • Feature Class Name

  • Geometry Type

  • Count of features


๐Ÿง  Why Use This Script?

  • Quickly summarize large collections of geospatial data

  • Useful for data validation, inventory, and reporting

  • Automates a task that would otherwise require repetitive clicks in ArcGIS Pro or Catalog

  • Clean and exportable format (CSV) ready for Excel or reporting tools


๐Ÿงพ The Code

python
import arcpy import os import csv # === USER INPUT === # Folder containing GDBs folder_path = r"C:\Path\To\Your\GDBs" # Update this path # Output CSV path csv_file = os.path.join(folder_path, "FeatureClass_Counts.csv") # Define CSV headers csv_headers = ['GDB Path', 'GDB Name', 'Dataset', 'Featureclass Name', 'Shape Type', 'Count'] # Open the CSV file for writing with open(csv_file, mode='w', newline='', encoding='utf-8') as file: writer = csv.writer(file) writer.writerow(csv_headers) # Walk through the directory tree for root, dirs, files in os.walk(folder_path): for dir_name in dirs: if dir_name.endswith('.gdb'): gdb_path = os.path.join(root, dir_name) arcpy.env.workspace = gdb_path print(f"Processing GDB: {dir_name}") # 1. Standalone feature classes for fc in arcpy.ListFeatureClasses(): fc_path = os.path.join(gdb_path, fc) desc = arcpy.Describe(fc) shape_type = desc.shapeType count = int(arcpy.GetCount_management(fc)[0]) writer.writerow([gdb_path, dir_name, 'None', fc, shape_type, count]) # 2. Feature classes inside datasets datasets = arcpy.ListDatasets('', 'Feature') or [] for dataset in datasets: for fc in arcpy.ListFeatureClasses(feature_dataset=dataset): fc_path = os.path.join(gdb_path, dataset, fc) desc = arcpy.Describe(fc_path) shape_type = desc.shapeType count = int(arcpy.GetCount_management(fc_path)[0]) writer.writerow([gdb_path, dir_name, dataset, fc, shape_type, count]) print(f"\n✅ Feature counts exported to CSV:\n{csv_file}")

๐Ÿ’ก Key Points to Remember

  • The script automatically scans all .gdb files in the given directory and subdirectories.

  • It distinguishes between standalone and dataset-based feature classes.

  • Each feature class's geometry type and feature count are captured.

  • Results are written to a CSV file—easy to share or import into Excel.


✅ Use Case Scenarios

  • Preparing for data migration

  • Performing a QA/QC audit

  • Generating summary reports

  • Checking for unexpected empty layers

  • Monitoring data growth across projects