I'm trying to create a list of features classes inside of our LGIM database for handouts to staff. I can successfully print out a list of all of the feature classes using the code below, but I want to only list feature classes that have content in them. Does anyone have a script they could share? Or has anyone done this before? If it helps, the data I'm trying to access is in SDE.
Code:
import arcpy
import os
arcpy.env.workspace = "c:/base/gdb.gdb"
datasets = arcpy.ListDatasets(feature_type='feature')
datasets = [''] + datasets if datasets is not None else []
for ds in datasets:
for fc in arcpy.ListFeatureClasses(feature_dataset=ds😞
path = os.path.join(arcpy.env.workspace, ds, fc)
print(path)
Heya Justin,
Check out the code example for the Data Access Walk function:
Walk—Help | ArcGIS for Desktop
It will let you quickly list all your feature classes without needing separate code to peek in each feature dataset. Once you've got a nice list of all feature classes, you can identify which ones are populated with at least one feature using Get Count—Data Management toolbox | ArcGIS Desktop. Note with Get Count that you need to access the result as an integer in your script. So use something like:
for fc in fcs:
if int(arcpy.GetCount_management(fc).getOutput(0)) > 0:
print(fc)
Happy listing!
Micah