Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
    
you'll probably need to reduce your code to the simplest possible snippet that still shows the error and add that to your post. There's too many things which could be happening to troubleshoot from what you've said so far. –  matt wilkie Mar 9 '11 at 0:46
    
error 000372 is feature class doesn't exist or is not supported. As written the if gp.GetCount() test will always be non-zero as the GetCount function returns an object, not a number (try print gp.GetCount(iter)). That's why the result and int lines are needed. –  matt wilkie Mar 9 '11 at 18:15

2 Answers 2

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    
share|improve this answer
    
Thanks for the answer, but as I didn't understand what the Searchcursor does, I didn't understand how to implement your code into mine to try and see if this is the problem. –  jonatr Mar 9 '11 at 11:09
    
Thanks for your help, amasephy, I tried your code (above) but now I got a different error: type 'exceptions.RuntimeError'>: ERROR 999999: Error executing function.Failed to execute (Script1). –  jonatr Mar 9 '11 at 14:56
    
Try running your code in IDLE and see what it highlights as being the problem. Use print statements (instead of gp.AddMessage) on path and iter to make sure they have the expected values. Also, I just noticed that you have a space between the gp and the .AddMessage in your code which may be the problem. –  amasephy Mar 9 '11 at 15:18
    
Thanks. Tried it, and it succeeds printing the path of the full FC, but fails when dealing with the empty one and gives the same Error 999999:<module> rows = gp.SearchCursor(path) RuntimeError: ERROR 999999: Error executing function. Oh, and I deleted the space. Thanks again. –  jonatr Mar 9 '11 at 15:37
    
Is it printing the expected value for iter? I just did a quick test on copying an empty shapefile and it worked just fine, it just warned me that the output file would be empty. I'm not really familiar with dictionaries but in this case I think a list would be more practical. Try using this: cop_list = ["rozetta", "height_line", "walls_fences"]. Then do for fc in cop_list: then put in the copy code and get rid of everything else. –  amasephy Mar 9 '11 at 16:38

Try something like this (tested on an arc10 machine, so results may vary. Adapted from GetCount Data Management).

import arcgisscripting
gp = arcgisscripting.create(9.3)
gp.workspace = 'D:/s/temp.gdb'
fcs = gp.listFeatureClasses()

for fc in fcs:
    print fc
    result = gp.GetCount_management(fc)
    count = int(result.GetOutput(0))
    print count
    if count > 0:
        # more than zero records, we can do something
share|improve this answer
    
Thanks Matt, but before I added My script (above), I tried implementing the 8-9 rows from your code into my script and still got the same error (ERROR 000732) –  jonatr Mar 9 '11 at 11:08
    
@jonatr, you've accepted this answer. Does that mean the comment above about this not working for you is no longer true? If that's the case please delete the comment as it could be confusing to others (and I'm happy to hear your problem is solved! :-) –  matt wilkie Mar 28 '11 at 20:20
    
as the second edit is the most updated, and the problem wasn't solved (as the problem was error 000732 and not empty FC, as it turns out), I've retrieved the "answer acceptance". As the problem, apperantly was a bit different than the title, do you want me to completly change the question, or leave it alone (I'de hate erasing your answers as they were big help even if they did solve it eventually). –  jonatr Mar 29 '11 at 11:01
    
I would leave it as is. The commentary shows the evolution of the problem and the solutions provided did reveal a deeper issue, and answer the subject line. As is often the case that the actual problem is not what we thought it was when we started out! –  matt wilkie Mar 29 '11 at 16:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.