1

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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 8, 2018 at 15:37
2
  • 3
    if not arcpy.Exists(out_feature_class): Commented Nov 8, 2018 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. Commented Nov 12, 2018 at 3:07

1 Answer 1

1

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

answered Nov 8, 2018 at 20:28
1
  • 2
    Yeah although this wouldn't cause error it would double the processing. Commented Nov 9, 2018 at 6:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.