Select to view content in your preferred language

Delete Feature Class if no Geometry Exists

3892
12
05-29-2012 01:29 PM
StuartBlumberg
Emerging Contributor
Hi,

I have a model using ModelBuilder that extracts data from an SDE database into a new personal geodatabase that the user creates.  I don't want to include any feature classes that have no geometry.  Is there a way to check all feature classes for geometry and delete the ones without using ModelBuilder?  The tool also extracts tables from spatial features from the SDE, is there a way to check if data exists in these tables and if not then delete them?  I am using ArcGIS 9.3.1.  Thank you.
0 Kudos
12 Replies
MathewCoyle
Honored Contributor
You can use a where clause in your export of shapefield is null.
0 Kudos
StuartBlumberg
Emerging Contributor
Mathew,

I am using "feature class to feature class" tool to export the layers from SDE to the geodatabase.  Do I need to add something (null) to the 'expression' box inside the "feature class to feature class" tool to omit the layer if it has no geometry?  Thanks for your help.
0 Kudos
MathewCoyle
Honored Contributor
Something like this. Where SHAPE.AREA is the name of your shape field to test if it is null.
"SHAPE.AREA IS NOT NULL"
0 Kudos
StuartBlumberg
Emerging Contributor
Mathew,

using that expression does not seem to prevent the feature class from being created.  It still creates the feature class with empty geometry.  Is there another approach?  Thanks.
0 Kudos
MathewCoyle
Honored Contributor
Is your geometry null or zero? You'll have to query based on the particulars of your data.
0 Kudos
StuartBlumberg
Emerging Contributor
Mathew,

The feature class is completely empty, there are no rows in the attribute table.  Thanks.
0 Kudos
MathewCoyle
Honored Contributor
An empty feature class is very different than a feature class with no geometry. If you want to completely avoid exporting an entire feature class if it has no rows, use the get count method.

count = arcpy.GetCount_management(fc)
if count > 0:
    #export
0 Kudos
StuartBlumberg
Emerging Contributor
I see, I was using the wrong term, thanks for clarifying!  Unfortunately we are still on 9.3.1 so Arcpy will not work, is there a way to do it otherwise using sql?  Thanks.
0 Kudos
MathewCoyle
Honored Contributor
Get Count is available for 9.3 as well. It just requires slightly different commands I believe.

Example
result = gp.GetCount_management("roads")
count = int(result.GetOutput(0))
0 Kudos