<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: assignment in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/assignment/m-p/672974#M52056</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Were you able to figure it out?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 08 Oct 2013 17:13:51 GMT</pubDate>
    <dc:creator>JohnMaddox</dc:creator>
    <dc:date>2013-10-08T17:13:51Z</dc:date>
    <item>
      <title>assignment</title>
      <link>https://community.esri.com/t5/python-questions/assignment/m-p/672972#M52054</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Parsing rhinoceros sightings&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Challenges&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The rhinos in the spreadsheet appear in no guaranteed order, and not all the rhinos appear at the beginning of the spreadsheet. As I parse each line, I must determine which rhino the reading belongs to and update that rhino's polyline track accordingly. I am not allowed to sort the Rhino column in Excel before I export to the CSV file. My script must be "smart" enough to work with an unsorted spreadsheet in the order that the records appear.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I do not immediately know how many rhinos are in the file or even what their names are. Although I could visually comb the spreadsheet for this information and hard-code each rhino's name, your script is required to handle all the rhino names programmatically. The idea is that I should be able to run this script on a different file, possibly containing more rhinos, without having to make many manual adjustments.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If I do things right, my polylines should look like this (points are included only for reference):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm having the most problems with the dictionaries&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;part of my code so far but no luck:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;rhinoName = {('Rhino'):(Rhino, array)}:&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for each Rhino in rhinoname:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dictionary[rhinoName].append([latValue, lonValueIndex])&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if rhinoName not in dictionary:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dictionary[rhinoName] = []&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dictionary[rhinoName]= ([latValue, lonValue])&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 27 Nov 2011 14:58:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assignment/m-p/672972#M52054</guid>
      <dc:creator>Stephaniejohnson2</dc:creator>
      <dc:date>2011-11-27T14:58:01Z</dc:date>
    </item>
    <item>
      <title>Re: assignment</title>
      <link>https://community.esri.com/t5/python-questions/assignment/m-p/672973#M52055</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have this same assignment and am receiving an error saying "unbound method add() must be called with Array instance as first parameter" (got type instance instead).&amp;nbsp; I am not sure what this means.&amp;nbsp; Here is my code below.&amp;nbsp; The error is for the second time I called "coordArray.add(coord)".&amp;nbsp; Also, if there are any other obvious problems with my code (although this is just a scratch draft so far) feel free to comment.&amp;nbsp; I have yet to have the script deal with the spatial reference and the text "name" field as required by the assignment.&amp;nbsp; Thank you for your help!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Reads rhino positions from an Excel-originating CSV file
#&amp;nbsp; and writes them to a pre-existing shapefile
import arcpy
from arcpy import env"
import fileinput
import string
import os

env.overwriteOutput = True

# Hard code file paths
spreadsheet = "C:/WCGIS/Geog485/Lesson4/RhinoObservations.csv"

# Sample of data
###Observer,X,Y,Rhino,Comments
##Ben,26.99391,-19.10447,Bo,
##Ben,27.00071,-19.1089,Tulip,Bathing
##Ben,26.9919,-19.10511,Bo,
##Ben,27.00071,-19.1059,Tulip,
##Ben,26.96809,-19.09578,Patches,
##Ben,26.97808,-19.11016,Dinky,
##Ben,26.99213,-19.10395,Bo,
##Ben,27.00083,-19.10326,Tulip,
##Ben,26.97038,-19.09863,Patches,Not doing much of anything
##Ben,26.97768,-19.11153,Dinky,
##Ben,26.99107,-19.10421,Bo,
##Ben,27.00138,-19.1021,Tulip,
##Ben,26.97122,-19.0991,Patches,
##Ben,26.97551,-19.11269,Dinky,
##Ben,26.9904,-19.10553,Bo,
##Ben,26.99893,-19.10342,Tulip,

# output feature class??&amp;nbsp; feature class doesn't exist yet, so not sure how to do this??
fcname = "C:/WCGIS/Geog485/Lesson4"
outname = "C:/WCGIS/Geog485/Lesson4/Rhino.shp"



# Open the CSV file &amp;amp; read the header line
observations = open(spreadsheet, "r")
headerline = observations.readline()
fieldList = headerline.split(",")

###&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 1 2&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4
### Observer,X,Y,Rhino,Comments
# Look through the header to find "X", "Y" and the "Rhino" field indices
rhinoIndex = fieldList.index("Rhino")
xIndex = fieldList.index("X")
yIndex = fieldList.index("Y")
## print "Rhino "+str(rhinoIndex) +" X "+str(xIndex)+" Y "+str(yIndex)

# Create a list / array for RhinoTracks
rhinoTracks = {}

# create the output feature class
arcpy.CreateFeatureclass_management ("C:/WCGIS/Geog485/Lesson4", "Rhino.shp", "POLYLINE")

# open an insert cursor for the new feature class
cur = arcpy.InsertCursor(outname)

# Loop through the rest of the file to read in all of the rhinos
for line in observations.readlines():
 ##Ben,26.99391,-19.10447,Bo,
 segmentedLine = line.split(",")
 rhino = segmentedLine[rhinoIndex]
 #print rhino
 # If rhino exists in dictionary - get the array from its key &amp;amp; add a point
 if rhino in rhinoTracks:
&amp;nbsp; coordArray = rhinoTracks[rhino]
&amp;nbsp; # create a new row or feature, in the feature class


&amp;nbsp; ## coordArray { [x,y] }
&amp;nbsp; lineArray = arcpy.Array()
&amp;nbsp; coord = arcpy.Point
&amp;nbsp; coord.X = segmentedLine[xIndex]
&amp;nbsp; coord.Y = segmentedLine[yIndex]
&amp;nbsp; ## add point to coordinate array
&amp;nbsp; coordArray.add(coord)
&amp;nbsp; #print "Rhino is "+rhino+" added point "+str(segmentedLine[xIndex])+" "+str(segmentedLine[yIndex])
&amp;nbsp; ## coordArray { [x,y],[x1,y1] }

&amp;nbsp; feat = cur.newRow()

&amp;nbsp; # set the geometry of the new feature to the array of points
&amp;nbsp; feat.shape = lineArray

&amp;nbsp; #insert the feature
&amp;nbsp; cur.insertRow(feat)
&amp;nbsp; lineArray.removeAll()
&amp;nbsp; lineArray.add(coord)

 # If rhino doesn't exist in dictionary - make a new array &amp;amp; add a point
 else:
&amp;nbsp; 
&amp;nbsp; cur = arcpy.InsertCursor(outname)&amp;nbsp; 
&amp;nbsp; ## Create a coordinate array
&amp;nbsp; coordArray = arcpy.Array
&amp;nbsp; ## Create a point object
&amp;nbsp; coord = arcpy.Point
&amp;nbsp; coord.X = segmentedLine[xIndex]
&amp;nbsp; coord.Y = segmentedLine[yIndex]
&amp;nbsp; ## add point to coordinate array
&amp;nbsp; coordArray.add(coord)

&amp;nbsp; feat = cur.newRow()

&amp;nbsp; # set the geometry of the new feature to the array of points
&amp;nbsp; feat.shape = lineArray

&amp;nbsp; #insert the feature
&amp;nbsp; cur.insertRow(feat)
&amp;nbsp; lineArray.removeAll()
&amp;nbsp; lineArray.add(coord)&amp;nbsp; 
&amp;nbsp; ## add coordinate array to my Dictionary (list of rhinos)
&amp;nbsp; rhinoTracks[rhino] = coordArray&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:24:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assignment/m-p/672973#M52055</guid>
      <dc:creator>CariePigeon</dc:creator>
      <dc:date>2021-12-12T04:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: assignment</title>
      <link>https://community.esri.com/t5/python-questions/assignment/m-p/672974#M52056</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Were you able to figure it out?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Oct 2013 17:13:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assignment/m-p/672974#M52056</guid>
      <dc:creator>JohnMaddox</dc:creator>
      <dc:date>2013-10-08T17:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: assignment</title>
      <link>https://community.esri.com/t5/python-questions/assignment/m-p/672975#M52057</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Things like &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;coordArray = arcpy.Array&lt;/SPAN&gt;&lt;SPAN&gt; should really be &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;coordArray = arcpy.Array()&lt;/SPAN&gt;&lt;SPAN&gt;, note the parens at the end.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Oct 2013 17:40:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/assignment/m-p/672975#M52057</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2013-10-08T17:40:25Z</dc:date>
    </item>
  </channel>
</rss>

