I am creating a shapefile based on three columns in my CSV File - Latitude, Longitude, and Laps. For the most part, I understand how to loop through the data and create the many points based on the latitude and longitude column, but I am having issues with my Laps column. I need to be able to loop through the data but exclude blank columns. Below is a sample of my data from the CSV File. The row that needs to be excluded is the row with the total Lap time for that Lap (i.e. #Lap 0...)
Below is my code that I am using. When I run it, I get an Error 99999: Something unexpected has caused the tool to fail.
# This script reads GPS tracks in CSV format and # writes the geometries (polyline) from the list of coordinate pairs import csv import arcpy def addPolyline(fc, array, sr): polyline = arcpy.Polyline(array, sr) with arcpy.da.InsertCursor(fc, ("SHAPE@",)) as cursor: cursor.insertRow((polyline,)) array.removeAll() # setup workpace to save the file arcpy.env.workspace = r"C:\\" # setup the feature class and spatial reference polylineFC = "carpath.shp" sr = arcpy.SpatialReference("GCS_WGS_1984") arcpy.CreateFeatureclass_management(arcpy.env.workspace, polylineFC, "POLYLINE", spatial_reference = sr) spatialref = arcpy.Describe(polylineFC).spatialReference # open the input file wakefieldRaceWay = open (arcpy.env.workspace + "\WakefieldParkRaceway_20160421.csv", "r") # setup csv reader and process the header csvReader = csv.reader(wakefieldRaceWay) header = next(csvReader) latIndex = header.index("Latitude") lonIndex = header.index("Longitude") lapIndex = header.index("Lap") # create an array vertices = arcpy.Array() # create a loop to iterate over lines but # exclude lines that have zero data in them for row in csvReader: isLap = row[lapIndex] if isLap == '\n': if vertices.count> 0 : addPolyline(polylineFC, vertices, spatialref) # Loop through the lines in the file and get each coordinate # put the coordinates into a tuple and add it to the list Latitude = row[latIndex] Longitude = row[lonIndex] vertex = arcpy.Point(Latitude, Longitude) vertices.add(vertex) # add the last segment manually addPolyline(polylineFC, vertices, spatialref)