I am working on building polylines from an array of points I have created from a csv file and am completely lost in building the lines. My code works as follows: I have the point array working, I need help in creating the polylines from the point array. Please note I am also wanting to add the name into the new polyline feature.
# Reads a csv file to create points of locations
import arcpy
print "==============RESTART===================="
# Set up variables
spreadsheet = "C:\Users\Desktop\RhinoObservations2.csv" # input file with coordinates
ouputFC = Rhino_Path # defines the name of the ouput feature class
# Open the CSV file and read the header line. "r" is read the file
observationsFile = open (spreadsheet, "r")
print observationsFile
headerLine = observationsFile.readline() # reads all lines in CSV??
print headerLine
# Determine the indicies of the columns "X","Y","Rhino"
fieldList = headerLine.split(",")
print fieldList
xIndex = fieldList.index("X")
print xIndex
yIndex = fieldList.index("Y")
print yIndex
rhinoIndex = fieldList.index("Rhino")
print rhinoIndex
# Set up new dictionary where the Rhino information is stored
rhinoDictionary = {}
# Loop through the remaining line of the input file; for each line....
for line in observationsFile.readlines():
print line
# Determine the rhino name, X,Y coordintes from that line
segmentedLine = line.split(",")
rhino = segmentedLine[rhinoIndex]
x = segmentedLine[xIndex]
y = segmentedLine[yIndex]
# Create an object of the the class Point (defined in the arcpy module) for the X Y coordinate
coords = arcpy.Point(x,y)
# If this rhino is not already in the dictionary
if not rhino in rhinoDictionary:
# Create a new object of class Array, add the object point, and then put array into dictionary
# under the name of the Rhino
coordArray = arcpy.Array() #setting up an empty list to store points
coordArray.add(coords) #list that contains one point
rhinoDictionary[rhino] = coordArray
# Else
else:
# Get the array object from the dictionary for this Rhino and add the point to the array.
coordArray = rhinoDictionary[rhino]
coordArray.add(coords)
# Print out the information in the dictionary
for key in rhinoDictionary:
print key
print "This is the point array: " + str(rhinoDictionary[key])
for p in rhinoDictionary[key]:
print "(" + str(p.X) + ", " + str(p.Y) + ")"
# Take the array and create polylines from it.
print "========"
# Create polylines and add them to the feature class