I am trying to create a shapefile from a text file that has the X, Y coordinates and an additional field for an attribute.
Example,
42.05323833668680,-92.55533115727803,1.00
42.71293930381023,-92.20234874538450,0.75
43.52984639634028,-91.56604875561564,0.75
I have found a lot of code and examples on how to read in the X,Y pair and create the Point shapfile from the pair, but not how to also bring in the additional variable and its values. Can someone help me out? I am able to create a new field called maxSize without a problem, but tried to add the value using, pnt.maxSize = maxSize and that doesn't work
Here is what I have,
import sys, os, string, csv, re, arcgisscripting
gp = arcgisscripting.create()
gp.OverWriteOutput = True
# Set workspace
gp.workspace = "C:/Hail"
# Set local variables
out_path = "C:/Hail"
out_name = "points.shp"
geometry_type = "POINT"
template = "DISABLED"
has_m = "DISABLED"
has_z = "DISABLED"
#Creating a spatial reference object
spatial_reference = gp.CreateSpatialReference('C:/Program Files/ArcGIS/Coordinate Systems/Geographic Coordinate Systems/World/WGS 1984.prj')
#Execute CreateFeatureclass
gp.CreateFeatureclass_management(out_path, out_name, geometry_type, '#', has_m, has_z, spatial_reference)
gp.AddField_management("points.shp", "maxSize", "DOUBLE", 11, 4)
f = open("C:/Hail/30minpts.txt")
csvReader = csv.reader(f, delimiter=',', quotechar='|')
for row in csvReader:
xCoord = row[0]
yCoord = row[1]
maxSize = row[2]
print(xCoord,yCoord,maxSize)
cur = gp.InsertCursor(out_name)
row = cur.NewRow()
pnt = gp.CreateObject('POINT')
pnt.x = xCoord
pnt.y = yCoord
pnt.maxSize = maxSize
row.shape = pnt
cur.InsertRow(row)
del cur,row,pnt,gp
f.close()