I have a text file with X and Y coordinates, as well as a third piece of information. I'm trying to create a point feature class from this text file by use of an insert cursor. I'm working with "SHAPE@XY"
token, but can't figure out the exact syntax. What am I doing wrong?
Pertinent code:
#Open text file
textFile = open (inFile, "r")
#Get X, Y, and PGA
lines = [r.split (" ")[0:3] for r in textFile]
#Spatial reference
SR = SpatialReference ("WGS 1984")
#Create point feature class
CreateFeatureclass_management (outPath, outName, "POINT", spatial_reference = SR)
#Add PGA field
AddField_management (outFc, "PGA", "FLOAT")
#Create insert cursor object
cursor = InsertCursor (outFc, ["SHAPE@XY", "PGA"])
for X, Y, PGA in lines:
#XY tuple
XY = (float(X), float(Y))
#Create row tuple
row = (XY, float(PGA))
print row
#Insert row
cursor.insertRow (row)
The first line prints as I would expect:
((-123.224, 38.4105), 0.02)
But the next line throws the following error:
Traceback (most recent call last):
File "C:/Users/e1b8/Desktop/E1B8/DASH_GIS_Integration/Calculate_PGA_per_plat_Point.py", line 277, in textToFeatureClass
cursor.insertRow (row)
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\arcobjects.py", line 106, in insertRow
return convertArcObjectToPythonObject(self._arc_object.InsertRow(*gp_fixargs(args)))
RuntimeError: Error in InsertRow
Three sample lines from the text file:
-123.2240 38.4105 0.02 0.01 1
-123.2157 38.4105 0.02 0.01 1
-123.2073 38.4105 0.02 0.01 1
import
used should always be included in code snippets presented here, and why I rarely use the "variant of the import statement that imports names from a module directly into the importing module’s symbol table." (docs.python.org/2/tutorial/modules.html). I think just usingimport arcpy
makes code more readable and easy to debug. – PolyGeo♦ Jul 28 '15 at 22:35da
. – Emil Brundage Jul 28 '15 at 22:35