Saturday, May 1, 2010

Another Update

-Just figured out how to convert .csv files into .dbf format via ArcCatalogue

Python Script I have so far:
# Most of it referenced from this tutorial
# There are some functions in the tutorial that returned an error when I tried to run it. This might be a version issue.

import sys, string, os, arcgisscripting

gp = arcgisscripting.create(9.3)

gp.Overwriteoutput = 1



#Specify the location for the new shapefile.

#gp.CreateFeatureclass("C:/Users/Alice/Desktop/Testing", "test_line.shp", "POLYLINE")




#Define Coordinate System

gp.workspace = "C:/Users/Alice/Desktop/Testing"

gp.toolbox = "management"

coordsys = "Coordinate Systems/Geographic Coordinate Systems/World/WGS 1984.prj"

gp.defineprojection("test_line.shp", coordsys)



#Open a cursor to insert rows into the shapefile.

cur = gp.InsertCursor("C:/Users/Alice/Desktop/Testing/test_line.shp")



#Create an Array and Point object.

lineArray = gp.CreateObject("Array")

pnt = gp.CreateObject("Point")



#Open a cursor on the table of XY coordinates to read from.

rows = gp.SearchCursor("C:/Users/Alice/Desktop/Testing/pythonTest.dbf")



#Reset the cursor to the top.

row = rows.Next()



#Loop through each record in the XY table..



while row:



#Set the X and Y coordinates for origin vertex.

pnt.x = row.GetValue("Origin_x")

pnt.y = row.GetValue("Origin_y")



#Insert it into the line array

lineArray.add(pnt)



#Set the X and Y coordinates for destination vertex

pnt.x = row.GetValue("dest_x")

pnt.y = row.GetValue("dest_y")



#Insert it into the line array

lineArray.add(pnt)



#Go to next row in table.

row = rows.Next()



#Insert the new poly into the feature class.

feat = cur.NewRow()

feat.shape = lineArray

cur.InsertRow(feat)

lineArray.RemoveAll()



del cur, row, rows

Update May 1st

Right now the goal is to create a python script that plots the location on arcMap when given a longitude and latitude.