0

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.

  • I didn't think that was relevant, as I thought it would be assumed (since I didn't get errors on the input feature classes) that both tables are in the arcpy.env.workspace. The other data values are left at default so not needed. Basically, the first input table is actually created by the code (and I've verified that it did create it in the workspace). The second input table is also in the workspace. – Mathwiz Apr 12 at 16:50
  • 2
    @Mathwiz Please edit your question to add a testable code snippet, not just the one line. We don't know what else is going on in your code beforehand that may be a factor to the error. Please include information about each dataset, and where arcpy needs to find each one – Midavalo Apr 12 at 16:55
  • I can add more code, but I don't really know what is relevant here. – Mathwiz Apr 12 at 17:25
  • Have you added MMFSimplifyPt10 to map after the insertcursor and made sure it looks ok? Try Check Geometry on all inputs before intersect – BERA Apr 13 at 15:59
  • 1
    Yes, I did. But I just realized I can get the results I need by doing a spatial join and keeping only points in common instead of intersect and the spatial join works fine. It doesn't solve the intersect issue, but it solves my problem! :) – Mathwiz Apr 13 at 17:25

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.