2

As part of a longer script, I use this code:

import arcpy, os

Polygon = r"pathtoashapefile.shp"
workspace = r"path_to_a_folder"
output = os.path.join(workspace, "test.shp")
arcpy.Union_analysis(Polygon, output, "ALL", "#", "GAPS")

and I get the error:

Runtime error 
Traceback (most recent call last):
  File "test.py", line 6, in <module>
  File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\analysis.py", line 563, in Union
    raise e
RuntimeError: Object: Error in executing tool

And this is a super frustrating error because it gives me no additional information. I am only unioning with one polygon shapefile because I want to see overlaps between polygons within the shapefile. I have tried all of the following:

putting Polygon in a list like: [Polygon]

Putting Polygon in a list like: [Polygon, "#"]

putting Polygon in a string formatted: string = '"%s" #' % Polygon

I have checked that Polygon has data in it and is not null. I have checked that the path to Polygon and to workspace are valid. I have not gotten any error other than the 'line 563' error in all of my attempts.

  • mmm the union tool might require the layer to be a feature layer – ziggy Jun 27 '17 at 17:36
  • 1
    I could not give a definite reason why. but to use a tool like select by location in arcpy, the inputs must be feature layers – ziggy Jun 27 '17 at 17:50
  • 2
    Union does not need feature layers but what we need is a code snippet that works up to where you see this error and the line number where that fails. – PolyGeo Jun 27 '17 at 21:57
  • 1
    I agree with @PolyGeo, this question will probably only ever get answered if we see more code. I took your code and ran it on some test data with overlapping polygons and it ran without error. So assuming this code is correct it would suggest something else is causing a problem. The immediate thoughts are that you have set an environment setting such as extent or workspace that is causing some sort of conflict? – Hornbydd Jun 27 '17 at 22:30
  • 1
    I wonder if Polygon is a reserved word, you could rename your variable as a test. – klewis Jun 27 '17 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.