[GIS] Dealing with empty feature classes in a ArcGIS 9.3.1 Python script

arcgis-9.3arcpyerror-000732esri-geodatabase

I have a script that goes over all the feature classes within a geodatabase (in ArcGIS 9.3.1) and copies them. The problem (as far as I can understand) is that when the script goes to a empty feature class, the script fails and gives the following error:

: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset Parcels_border does not exist or is not supported
Failed to execute (CopyFeatures).

How can I get the code to skip over empty feature classes? I tried to do a GetCount() with a if clause – if empty then skip and so on – but even the GetCount() doesn't deal well with empty feature classes either(it puts out the same error).

Does anyone know how I can overcome this error?

EDIT: Hearing to Matt's advice, here's my script:

    # Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create(9.3)

# Load required toolboxes...
gp.AddToolbox("E:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")


# Local variables...
cop_dictionary = {"xxx":"rozetta","yyy":"height_line","zzz":"walls_fences"}                     

part_path = "I:\\Users\\john\\"  #setting part_path                         

for iter in cop_dictionary:                                     
    path = part_path + cop_dictionary[iter] + ".shp"   
    if (gp.GetCount(iter)!=0): 
        gp.CopyFeatures_management(iter, path, "", "0", "0", "0")                       
        gp .AddMessage(iter + "has been exported") 
    else:
        gp .AddMessage(iter + "Is Empty")

XXX,YYY,ZZZ are feature class (FC) names in a non-english font taken from a geodatabase which is opened in the ArcMap TOC. The non-english font is not a problem, as it runs through the first FC (XXX), and exports a intact shapefile. The error above appears in "YYY" which is a existing and empty FC.

Thanks a million.

SECOND EDIT: tried the 2 following answers below, both good (and teaching), but none of them solved the problem. It seems the problem isn't empty FC, but FC with some thing wrong in them (I can't pinpoint what). I haven't solved the problem , but left the problematic FC out until I figure out the problem.

Best Answer

I've run into that error a lot. Depending on how your script is setup to process each feature class,ie if it processes each one at a time you could try using a search cursor test. See below.

EDIT:

The search cursor in this case is looking at the first shape record of each feature class and seeing if it has a null value. If its null, then the feature class is empty because the shape can't be null as far as I know. Try this for your code:

REVISED CODE:

for iter in cop_dictionary:                                     
    path = part_path + iter + ".shp"   # I think all you need is iter here,
                                   # since the for loop handles the iteration
    rows = gp.SearchCursor(path)
    row = rows.next()

    value = row.Shape  #or row.SHAPE capitalization matters here!


    if value is None:
        #move onto next feature class
        gp.AddMessage(iter + "Is Empty")

    else:
        #copy feature class

        gp.CopyFeatures_management(iter, path, "", "0", "0", "0")                       
        gp.AddMessage(iter + "has been exported") 



    del rows, row    
Related Question