How to stop output of empty feature datasets with model

2278
4
07-27-2011 01:42 PM
markcrow
New Contributor
I have set up a simple model that will select features in a feature class (personal geodatabase) based on an expression and then output the selected features into a new feature class.  I have set up an iterator so that I can select the feature dataset and it will run the above described process on each feature class in said dataset.  The problem is that the model will create an output feature class whether the select criteria was met or not.  In other words, whenever there is a feature class that does not meet the criteria, nothing is selected, then it creates an empty feature dataset.  I want to either avoid the creation of these empty datsets, or delete them on the back end.  I can't figure out how to do either in model builder (I don't do code...sorry).  Image attached...I would greatly appreciate some help with this one.
0 Kudos
4 Replies
ChristopherBlinn1
Regular Contributor
Mark,

Unfortunately, the only way I see achieving this is to script in an If...Then conditional statement which will read a row count for all of your output feature classes.

If Feature Class Row Count = 0 Then
Delete Feature Class

I found this script on another forum that returns the row count, you may be able to easily change it run in your conditional statement:

totalRecordCount = int(gp.GetCount_management(gp.describe(featureLayer).catalogpath).getoutput(0))

Good Luck!
0 Kudos
ShitijMehta
Esri Regular Contributor
This is what you can try:


  • Use the iterator and connect the output feature class (green oval) as input to Make Feature Layer tool.

  • Use Make feature layer tool to make a selection based on your sql query. Connect the output to the Get Count tool.

  • Get Count tool (see help on this tool) - if there are any selected features the output of get count tool is 1 and the tool connected to it downstream will run. if no features are selected, and the count is 0, the output of get count will be 0 and the downstream will not run.

  • Copy features in the end with output of make feature layer tool as input to the tool and output of the get count as the precondition to the tool.


Hope this works for you.
0 Kudos
markcrow
New Contributor
That worked great!  Thanks for the help.
0 Kudos
HilalAl-Rajhi
New Contributor
0 Kudos