I am new to Python and trying to create a Polyline feature from Lat longs in a text file. Using answers to similar questions, below is the code I came up with. It doesn't throw an error but doesn't create polyline feature either. The LatLongs.txt contains three columns 1) unique identifier, 2) Latitude, 3) Longitude. Any help is greatly appreciated.
import arcpy
arcpy.env.overwriteOutput=1
array = arcpy.Array()
outFolder=r'C:\Temp'
fc = 'PolylineCSV.shp'
spatRef = arcpy.SpatialReference(4326)
arcpy.CreateFeatureclass_management(out_path=outFolder, out_name=fc,
geometry_type='POLYLINE',
spatial_reference=spatRef)
featureList = []
cursor = arcpy.InsertCursor("C:\\Temp\\PolylineCSV.shp")
feat = cursor.newRow()
coordinateList="C:\\Temp\\LatLongs.txt"
with open(coordinateList) as f:
for line in f:
SplitLine = line.split(',')
x = float(SplitLine[2]) #Get longitude
y = float(SplitLine[1]) #Get latitude
point = arcpy.Point(x,y)
array.add(point)
try:
nextline=next(f)
SplitnextLine = nextline.split(',')
x = float(SplitnextLine[2])
y = float(SplitnextLine[1])
point = arcpy.Point(x,y)
array.add(point)
polyline = arcpy.Polyline(array)
array.removeAll()
# Append to the list of Polyline objects
featureList.append(polyline)
feat.shape = polyline
# Insert the feature
cursor.insertRow(feat)
except StopIteration as e:
print("error handled")
del feat
del cursor