I have a CSV file which contains lat long coordinates which represent a car doing laps around a racetrack. At the end of each lap, there is a row in the CSV file which marks the end of the lap and does not follow the same format as the rest of the rows within the file. An example of such row would be "# Lap 1". I am trying to read through the file, pull out the lat long values, and create a polyline feature class which will display each of the laps. I have been able to create a single polyline but have not been able to create multiple polylines. I am trying to write the code so that when it recognizes the "#" at the beginning of the line, it will skip reading the line and start a new polyline.
I keep receiving the error "RuntimeError: Point: Input value is not numeric".
I'm fairly new to Python and I'm not sure where to go from here. I would really appreciate any help or input.
Here is my code as it stands currently:
import csv import arcpy #Function that creates polyline def addPolyline(fc, array, sr): polyline = arcpy.Polyline(array, sr) with arcpy.da.InsertCursor(fc, ("SHAPE@",)) as cursor: cursor.insertRow((polyline,)) array.removeAll() arcpy.env.overwriteOutput = True arcpy.env.workspace = r"C:\GEOG 485\Lesson4" gpsTrack = open(arcpy.env.workspace + "\WakefieldParkRaceway_20160421.csv", "r") lineFC = "laplines.shp" sr = arcpy.SpatialReference(4326) arcpy.CreateFeatureclass_management(arcpy.env.workspace, lineFC, "POLYLINE", spatial_reference = sr) spatialRef = arcpy.Describe(lineFC).spatialReference csvReader = csv.reader(gpsTrack) header = next(csvReader) latIndex = header.index("Latitude") lonIndex = header.index("Longitude") timeIndex = header.index("Time") #Create an empty array object vertexArray = arcpy.Array() #Loop through the line in the file and get each coordinate for row in csvReader: if row[timeIndex].startswith("#"): if vertexArray.count > 0: addPolyline(lineFC, vertexArray, spatialRef) lat = row[latIndex] lon = row[lonIndex] vertex = arcpy.Point(lon, lat) vertexArray.add(vertex) #Add polyline addPolyline(lineFC, vertexArray, spatialRef)