Doing an intersection and some files already exist.Is it possible to tackle this error specifically and not with try except in general?

try:
    for i in cur:
        Intersect_analysis (in_features, out_feature_class)
except arcpy.ExecuteError as e:
    print(e)
    pass

file already exists.

This may pass any execute error instead of just this with a file being already there.

OR

Since the above error stopped the whole program and now has to restart, another plan would be to search in the gdb which feature layers aren't there and proceed to do the intersect only to the new ones that haven't been processed due to the program stop.

  • 3
    if not arcpy.Exists(out_feature_class): – Tom Nov 8 at 15:41
  • I think @Tom has the answer but if the feature class exists but contains no features due to a previous failure it would still be skipped, you could include elif int(arcpy.GetCount_management(out_feature_class).getOutput(0)) == 0: arcpy.Delete_managment(out_feature_class) then arcpy.Intersect_analysis (in_features, out_feature_class) to be sure the empty feature class is because there are no intersecting features and not a failure in the geometry engine. – Michael Stimson Nov 12 at 3:07
up vote 0 down vote accepted

You can tell arcpy to overwrite any outputs if you wish:

The following should do the trick:

   >>> from arcpy import env
   >>> env.overwriteOutput = True

http://desktop.arcgis.com/en/arcmap/latest/analyze/executing-tools/setting-environments-at-the-python-window.htm

  • 2
    Yeah although this wouldn't cause error it would double the processing. – user51332 Nov 9 at 6:59

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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