This is carrying forward from the previously asked Creating Polyline shapefile from text file using ArcPy?
With further insight from a colleague, I have the following code that I feel is a good start to creating a polyline file from a text file. However; I need to alter it, so it will break up the text file by line and populate the shapefile with the attributes.
import arcpy
arcpy.env.workspace = "C:\\Data"
outFolder = "C:\\_Data"
fc = "Paths.shp"
spatRef = arcpy.SpatialReference(26913)
arcpy.CreateFeatureclass_management(outFolder, fc, "POLYLINE", "", "", "", spatRef)
pointList = arcpy.Array()
with open("C:\\Paths.txt",'r') as coordinateList:
with arcpy.da.InsertCursor(fc, ["SHAPE@"]) as cursor:
for line in coordinateList:
SplitLine = line.split(",")
x = float(SplitLine[1])
y = float(SplitLine[2])
point = arcpy.Point(x,y)
pointList.add(point)
polyline = arcpy.Polyline(pointList)
cursor.insertRow([polyline])
del cursor
coordinateList.close()
A sample of the text file is below (Name, coordx, coordy).
Ranch1_1, 529018.125025, 4108038.05548
Ranch1_1, 529005.718792, 4108028.20659
Ranch1_1, 528993.340503, 4108018.73931
Ranch1_1, 528980.990158, 4108009.65364
Ranch1_1, 528968.667757, 4108000.94958
Ranch1_1, 528956.373301, 4107992.62713
Ranch1_1, 528944.106788, 4107984.68629
Ranch1_1, 528931.86822, 4107977.12705
Ranch1_1, 528919.657595, 4107969.94943
Ranch1_1, 528907.474915, 4107963.15341
Ranch1_2, 529018.125025, 4108038.05548
Ranch1_2, 528994.381279, 4108036.02086
Ranch1_2, 528971.341496, 4108034.79222
Ranch1_2, 528949.005677, 4108034.36954
Ranch1_2, 528938.101754, 4108034.46044
Ranch1_2, 528927.373822, 4108034.75283
Ranch1_2, 528916.82188, 4108035.24671
Ranch1_2, 528906.44593, 4108035.94208
Ranch1_2, 528896.24597, 4108036.83895
Ranch1_2, 528886.222001, 4108037.93731