I'm trying to set an arcpy da insert cursor to iterate through a dictionary that adds in the rhino's name. I'm missing a code that would loop through the cursor.
def rhinoTracker(Rhino, X, Y, dictionary):
vertex = arcpy.Point(X, Y)
if Rhino in dictionary:
vertexArray = dictionary[Rhino]
vertexArray.add(vertex)
else:
vertexArray = arcpy.CreateObject("Array")
vertexArray.add(vertex)
dictionary[Rhino] = vertexArray
print "This the key {0}".format(Rhino)
print "These are {0}'s points {1}".format(Rhino, dictionary[Rhino])
print "{0} has {1} points".format(Rhino, str(len(dictionary[Rhino])))
import csv
import arcpy
arcpy.env.workspace = "E:\College\Penn State\GEOG 485\Lesson 4\JHorwitz_Lesson4_Submission\Shapefiles"
arcpy.env.overwriteOutput = True
Path = "E:\College\Penn State\GEOG 485\Lesson 4\JHorwitz_Lesson4_Submission\Shapefiles"
spatialpath = "E:\College\Penn State\GEOG 485\Lesson 4\JHorwitz_Lesson4_Submission\Shapefiles\MysteryState.shp"
RhinoObservation = open("E:\College\Penn State\GEOG 485\Lesson 4\JHorwitz_Lesson4_Submission\RhinoObservations.csv", "r")
arcpy.CreateFeatureclass_management(Path, "RhinoTrack.shp", "POLYLINE", "", "DISABLED", "DISABLED", spatialpath)
arcpy.AddField_management("RhinoTrack.shp", "Name", "TEXT")
rhinoLine = "E:\College\Penn State\GEOG 485\Lesson 4\JHorwitz_Lesson4_Submission\Shapefiles\RhinoTrack.shp"
spatialRef = arcpy.Describe(rhinoLine).spatialReference
csvReader = csv.reader(RhinoObservation, delimiter=",")
header = csvReader.next()
xIndex = header.index("X")
yIndex = header.index("Y")
rhinoIndex = header.index("Rhino")
rhinoList = {}
for row in csvReader:
Rhino = row[rhinoIndex]
X = row[xIndex]
Y = row[yIndex]
rhinoTracker(Rhino, X, Y, rhinoList)
with arcpy.da.InsertCursor(rhinoLine, ("SHAPE@")) as cursor:
for Rhino in cursor:
polyline = arcpy.Polyline(vertexArray, spatialpath)
cursor.insertRow((polyline,))
with arcpy.da.UpdateCursor("RhinoTrack.shp", "Name") as cursor:
for Name in cursor:
Name[0] = Rhino
cursor.updateRow(Name)
Between line 79-82, I need to use the insert cursor to iterate through a dictionary and I'm not sure how.