Select to view content in your preferred language

Deleting features with an empty output using iterate feature classes

334
2
Jump to solution
10-15-2024 07:05 AM
Labels (1)
PeterDouglassEPD
Emerging Contributor

I wonder if someone can help me. I want to create a model that will iterate datasets within a FGDB and delete all where there is an empty output, or whether someone could help with an initial batch clip iteration where any empty outputs generated are deleted. I have tried many ways in model builder but can't get it to work.

The model below is what I have for the former

PeterDouglassEPD_0-1729001114927.png

 

1 Solution

Accepted Solutions
Ed_
by MVP Regular Contributor
MVP Regular Contributor

this might help?

 

import arcpy

workspace = "path/to/your/geodatabase.gdb"
arcpy.env.workspace = workspace

for fc in arcpy.ListFeatureClasses():
    count = int(arcpy.GetCount_management(fc)[0])
    if count == 0:
        arcpy.Delete_management(fc)
        print(f"Deleted empty feature class: {fc}")

 

Question | Analyze | Visualize

View solution in original post

2 Replies
Ed_
by MVP Regular Contributor
MVP Regular Contributor

this might help?

 

import arcpy

workspace = "path/to/your/geodatabase.gdb"
arcpy.env.workspace = workspace

for fc in arcpy.ListFeatureClasses():
    count = int(arcpy.GetCount_management(fc)[0])
    if count == 0:
        arcpy.Delete_management(fc)
        print(f"Deleted empty feature class: {fc}")

 

Question | Analyze | Visualize
PeterDouglassEPD
Emerging Contributor

Amazing, thank you so much Ed!

0 Kudos