[GIS] Arcpy creating Polyline from dictionary values

arcpyarraycsvgeometryline

I am attempting to do the final project for the open source Penn state class https://www.e-education.psu.edu/geog485/node/144. The task is to parse a CSV file containing rhino coordinates and create a polyline.
I have written code that I believe should work but nothing gets created in the feature class

import csv
import arcpy
arcpy.env.overwriteOutput = True
file = 'C:\RhinoObservations.csv'
geodb = "C:\rhinotracks.gdb"
earthq = arcpy.CreateFeatureclass_management(geodb,"Rhino","POLYLINE",'','',"ENABLED",4326)
arcpy.AddField_management(earthq,"NAME","TEXT")
rhino = {}
with open(file, 'rb') as csvv:
    reader = csv.DictReader(csvv)
    for row in reader:
        if row['Rhino'] not in rhino:
            rhino[row['Rhino']] = []
        rhino[row['Rhino']].append((float(row['X']),float(row['Y'])))
with arcpy.da.InsertCursor(earthq,("NAME","SHAPE@XY")) as cur:
    for k,v in rhino.items():
        print k,v
        array = arcpy.Array()
        for coords in v:
            array.add(arcpy.Point(float(coords[0]),float(coords[1])))
        line = arcpy.Polyline(array,4326)
        row2 = (k,line)
        cur.insertRow(row2)
        

the script throws no error and create a feature class of the rhinos names but there are no polylines

enter image description here

I am using this post as a reference Creating arrays and polylines from dictionary using ArcPy?

when I print k,v the rhinos name has the correct XY pairs stored in their correct tuples. I do not know why there is no polyline showing up
this is the output for the Rhino Meredith when I print k,v. Tuple in a list

Meredith [(26.97808, -19.11016), (26.97768, -19.11153), (26.97551, -19.11269), (26.97657, -19.11343), (26.97607, -19.11448), (26.97434, -19.11438), (26.97311, -19.11301), (26.97378, -19.11269), (26.97412, -19.11175), (26.97479, -19.11085)]

Best Answer

Have a look at this page: http://pro.arcgis.com/en/pro-app/arcpy/classes/polyline.htm#C_GUID-FC2C3085-2C89-4CDB-985B-DFE78118B603

This has a code sample for creating a polyline.

Try this instead (changed the polyline creation and SHAPE field):

import csv
import arcpy
arcpy.env.overwriteOutput = True
file = 'C:\RhinoObservations.csv'
geodb = "C:\rhinotracks.gdb"
earthq = arcpy.CreateFeatureclass_management(geodb,"Rhino","POLYLINE",'','',"ENABLED",4326)
arcpy.AddField_management(earthq,"NAME","TEXT")
rhino = {}
with open(file, 'rb') as csvv:
    reader = csv.DictReader(csvv)
    for row in reader:
        if row['Rhino'] not in rhino:
            rhino[row['Rhino']] = []
        rhino[row['Rhino']].append((row['X'],row['Y']))
with arcpy.da.InsertCursor(earthq,("NAME","SHAPE@")) as cur:
    for k,v in rhino.items():
        print k,v
        line = arcpy.Polyline(arcpy.Array([arcpy.Point(*coords) for coords in v]))
        row2 = (k,line)
        cur.insertRow(row2)

You were using the SHAPE@XY token. This is the token for the feature's centroid. For the feature's geometry, you need to use the SHAPE@ token.