3

Is there a tool or script in ArcMap (currently using 10.5.1 basic) to identify empty feature classes without deleting them? I have to keep all feature classes in the geodatabase, even if they are empty, but I would like to know which ones actually have data without going through every feature class. There are up to 522 feature classes per geodatabase, with 100+ databases.

1
  • 2
    Welcome to GIS SE. As a new user, please take the Tour. You can certainly write your own in Python easily enough, in under twenty lines. If the feature classes are in an enterprise-enabled geodatabase, you might be able to send simple SELECT * ... LIMIT 1 queries via ArcSDESQLExecute, though file geodatabases would likely require arcpy's GetCount_management(). Please Edit the question to contain your code if you have difficulty.
    – Vince
    Commented Apr 30, 2018 at 14:15

2 Answers 2

5

You can run the code below in the Python window within ArcMap. You will first have to copy the path to the directory containing all of your geodatabases and insert it into the script at the identified location. That is, replace "path\Goes\Here" with your path.

import os, arcpy

# Copy the path to the directory containing your geodatabases and insert path
# in between the single quotes below, like "GDBs = r'D:\GIS Data\GDBs'"

GDBs = r'path\Goes\Here'

L = []
GDBList = []
for paths, directories, files in os.walk(GDBs):
    for dir in directories:
        L.append(os.path.join(paths, dir))
for i in L:
    if i.endswith('.gdb'):
        GDBList.append(i)
print GDBList

for GDB in GDBList:
    arcpy.env.workspace = GDB
    datasets = arcpy.ListDatasets()
    FCs = []
    for fc in arcpy.ListFeatureClasses():
        result = arcpy.GetCount_management(fc)
        print str(GDB) + ',' + str(fc) + ',' + str(result)

    for ds in datasets:
        for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
            result = arcpy.GetCount_management(fc)
            print str(GDB) + ',' + str(fc) + ',' + str(result)

This will create a comma separated list containing the geodatabase name, the feature class name, and number of features within the feature classes. This list can be copied from the Python window within ArcMap and pasted into a spreadsheet. This will not alter the data within the geodatabases in any way.

1
2

You can use GetCount_management to identify whether there are any feature classes with zero records.

Example usage:

# 1. Look for geodatabases in your environment to loop through
# http://pro.arcgis.com/en/pro-app/arcpy/functions/listworkspaces.htm
# 2. Loop through the geodatabases and identify feature classes
# http://pro.arcgis.com/en/pro-app/arcpy/functions/listworkspaces.htm
# (Note: may need to handle feature classes within feature datasets)
# http://pro.arcgis.com/en/pro-app/arcpy/functions/listdatasets.htm
# 3. Identify the empty feature classes 
for fc in fcs:
    numRows = int(arcpy.GetCount_management(fc).getOutput(0))  
    # http://pro.arcgis.com/en/pro-app/tool-reference/data-management/get-count.htm
    if numRows == 0:
        print('{} has {} records'.format(fc, numRows))
2
  • Won't work, converting to float is missing.
    – FelixIP
    Commented May 1, 2018 at 4:53
  • Good point @FelixIP; adjusted to use getOutput and to convert to integer value before if statement.
    – SMiller
    Commented May 1, 2018 at 13:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.