[Tutor] Parsing

Alan Gauld alan.gauld at btinternet.com
Mon Nov 28 01:51:27 CET 2011


On 27/11/11 20:45, Deanna Wilson wrote:
>
>       Project 4: Parsing rhinoceros sightings

OK, You've told us this is homework, and you appear to have made some 
start but we need some more information.

Can you program in any other language other than Python?
Which version of Python are you using? Obviously 2.X but which X?
Which OS are you running?
What is arcpy? It is not one of the standard Python libraries.

What is the arrray that you are trying to use? Its not a builtin type in 
Python and you don;t seem to import it from anywhere?

You are obviously allowed to use arcopy, so do we assume you could also 
use  the csv module to process the csv file?

Your rhinoName function is badly broken...
And addVertex is not used vbut duplicated in the code.
Inserting a few print statements at strategic places should help you see 
what is happening in your code.

Now where would you like us to start?


> sample of my code:
>
> import arcpy
>
> shapefile = "C:\\...shp"
> pointFilePath = "C:\\...csv"
> pointFile = open(pointFilePath, "r")
> lineOfText = pointFile.readline()
> dataPairList = lineOfText.split(",")
>
> def addVertex(lat, lon, array):
>      vertex = arcpy.CreateObject("Point")
>      vertex.X = lon
>      vertex.Y = lat
>      array.add(vertex)
>
> def addPolyline(cursor, array):
>     feature = cursor.newRow()
>     feature.shape = array
>     cursor.insertRow(feature)
>     array.removeAll()
>
> def rhinoName(Rhino, dictionary):
>      if rhinoName in rhinoDictionary:
>          dictionary[rhinoName].append([latValue, lonValueIndex])
>      if rhinoName not in dictionary:
>          dictionary[rhinoName] = []
>      else:
>          dictionary[rhinoName]= ([latValue, lonValue])
>
> latValueIndex = dataPairList.index("X")
> lonValueIndex = dataPairList.index("Y")
> vertexArray = arcpy.CreateObject("Array")
> for line in pointFile.readlines():
>      segmentedLine = line.split(",")
>      latValue = segmentedLine[latValueIndex]
>      lonValue = segmentedLine[lonValueIndex]
>      vertex = arcpy.CreateObject("Point")
>      vertex.X = lonValue
>      vertex.Y = latValue
>      vertexArray.add(vertex)
>      polylineArray.add(currentPoint)
>
> cursor = arcpy.InsertCursor(shapefile)
> row = cursor.newRow()
> row.Shape = vertexArray
> cursor.insertRow(row)
> del cursor

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list