Is there a bug in ArcPy? I have two features I want to intersect in a feature data set using ArcPy (this is a small part of a bigger program). Let me preface this by saying that when I do this in ArcMap 10.7 with the same two feature classes, it works perfectly. I need it to work in my program.
The code leading up to the intersect statement is below. All the code leading to the intersect statement works and the file used to intersect the buffer layer is created, the buffer layer is also in the workspace.
import arcpy
import math
filepath = r'C:\Users\aschi\TestPurposes.gdb\TestFeatureDataSet'
arcpy.env.workspace = filepath
sr = arcpy.Describe("MMFSimplifyPt10").spatialReference
# Add field to keep track of turns
arcpy.AddField_management("MMFSimplifyPt10", "turn_count", 'LONG')
arcpy.CreateFeatureclass_management(filepath,'MMFSimplifyPt10_Angles',"POINT",spatial_reference=sr)
arcpy.AddField_management('MMFSimplifyPt10_Angles','Angle',"DOUBLE")
arcpy.AddField_management('MMFSimplifyPt10_Angles','Trip_ID',"DOUBLE")
# Initiate insert cursor to store turn angles
Fields = ['SHAPE@', 'Angle','Trip_ID']
insCur = arcpy.da.InsertCursor("MMFSimplifyPt10_Angles",Fields)
def GetAngle(A, B, C):
distAB = B.distanceTo(A)
distBC = C.distanceTo(B)
distAC = C.distanceTo(A)
try:
cosangB = ((distAB * distAB) + (distBC * distBC) - (distAC * distAC)) / (2 * distAB * distBC)
angB = math.acos(cosangB)
except:
angB = math.pi
print 'Divide by zero error. Coinciding points, going to next.'
return angB
# Finds the angle at each vertex and stores those that are "small enough" to be possible turns.
with arcpy.da.SearchCursor("MMFSimplifyPt10", ["SHAPE@", "trip_id"]) as Scursor:
for row in Scursor:
for part in row[0]:
pt_count = 1
for pnt in part:
pnt = arcpy.PointGeometry(pnt, sr)
if pt_count > 1:
if pt_count > 2:
angle1 = GetAngle(twoBack, oneBack, pnt)
print angle1
if angle1 < 7*math.pi/9:
insCur.insertRow([oneBack, angle1, row[1]])
twoBack = oneBack
oneBack = pnt
pt_count += 1
del insCur
arcpy.Intersect_analysis(['MMFSimplifyPt10_Angles', 'TriCounty_Junctions_Buffer'], 'MMFSimplifyPt10_PTurns', output_type='POINT')
According to the documentation on intersect this is the correct syntax, the list is my two input features to be intersected, the second parameter is the output feature class to be created by "Intersect" and I want the output to be point data.
When I run the code I get the following error:
arcgisscripting.ExecuteError: ERROR 999999: Error executing function.
The table was not found.
The table was not found. [MMFSimplifyPt10_PTurns]
The table was not found.
The table was not found. [MMFSimplifyPt10_PTurns]
Invalid Topology [Topoengine error.]
Failed to execute (Intersect).
Process finished with exit code 1
Notice that the table that wasn't found is my output table that should be created by the Intersect tool. I've seen other posts here where people got this error but it was their input features. Also, I did try creating the output feature with a blank attribute table first and got the error that "MMFSimplifyPt10_PTurns" already exists.
Does anybody know of a way to fix this? It seems like if it works in ArcMap it should work in Python too, but it doesn't.
MMFSimplifyPt10
to map after the insertcursor and made sure it looks ok? Try Check Geometry on all inputs before intersect