I'm trying to add a text file of points to a feature class using insert-cursor and I can't seem to figure it out. I'm new to python and arcpy so this is a little confusing for me. the error message I get is below. if anything else is needed I will try and provide it.
the error message reads:
Traceback (most recent call last): File "L:\400\lab9data\InsertCursor_GPSPts.py", line 61, in theInsertCur.insertRow([newRow]) File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\arcobjects\arcobjects.py", line 106, in insertRow return
convertArcObjectToPythonObject(self._arc_object.InsertRow(*gp_fixargs(args)))
RuntimeError: Error in InsertRow
#import arcpy
import arcpy
#set up an insert cursor to write to the feature class you created in part 1. Variable name should be theInsertCur.
#1 ----------Add one line of code below-----------------------------
theInsertCur = arcpy.InsertCursor("l://400//lab9data1.1//lab9data//cursor.gdb//GPS_Pts//myyGPSpoints")
#a counter used to skip first heading line
theCnt = 1
#open the file and read each line using a loop
#2 ---------------Change file path below------------------
for theLine in open("l://400//lab9data1.1//lab9data//GPS_collection.txt", 'r'):
#We are skipping the heading line and then reading all other lines in the text file
if theCnt > 1:
#split the line into a list of three values
threeValues = theLine.split(',')
#print threeValues list to get an idea of what is happening
print(threeValues)
#get the x coordinate, y coordinate, and speed values from the threeValues list
theX = float(threeValues[0])
theY = float(threeValues[1])
theSpeed = float(threeValues[2])
#create a new point object with theX and theY as its coordinates. Variable name should be newPoint.
#see Professional Library - Geoprocessing - The ArcPy site package - Classes - Point
#3 ----------Add one line of code below-----------------------------
newPoint = arcpy.Point(theX, theY)
#add a row to InsertCursor. Variable name should be newRow.
##see Professional Library - Geoprocessing - The ArcPy site package - Functions - Cursors - InsertCursor
#4 ----------Add one line of code below-----------------------------
newRow = arcpy.InsertCursor("l://400//lab9data1.1//lab9data//cursor.gdb//GPS_Pts//myyGPSpoints")
#set the shape field value to the newPoint. The shape field name is 'Shape'
##see Professional Library - Geoprocessing - The ArcPy site package - Classes - Row
#5 ----------Add one line of code below-----------------------------
newPoint = theInsertCur.newRow()
#set the speed field value to theSpeed. The speed field name should be 'Speed'
##see Professional Library - Geoprocessing - The ArcPy site package - Classes - Row
#6 ----------Add one line of code below-----------------------------
theSpeed = theInsertCur.newRow()
#insert newRow using theInsertCur
##see Professional Library - Geoprocessing - The ArcPy site package - Functions - Cursors - InsertCursor
#7 ----------Add one line of code below-----------------------------
theInsertCur.insertRow(newRow)
#advance counter
theCnt = theCnt + 1
#delete references to cursor and row to clean up
#uncomment the code below if you are confident you have set the variables above
#to match what is in the code below.
##see Professional Library - Geoprocessing - The ArcPy site package - Functions - Cursors - InsertCursor
#8 ----------Uncomment below-----------------------
del theInsertCur
del newRow