AnsweredAssumed Answered

Adding XY Coordinates from a table (.csv) file into ArcMap using Python

Question asked by B00513467_GIS_Core on May 1, 2020
Latest reply on May 3, 2020 by bixb0012

I do not where I went wrong here. Please help me. 

 

import arcpy
import fileinput
import string
import os
from arcpy import env
env.workspace = "P:\GEOG - Programming in GIS\Final project\Data"
env.overwrightOutput = True
outpath = "P:\GEOG - Programming in GIS\Final project\Data"
newfc= "Results/NewPtssss.shp"
arcpy.CreateFeatureclass_management(outpath, newfc, "Point")
infile = "P:\GEOG - Programming in GIS\Final project\Data\coordinates.txt"
cursor = arcpy.da.InsertCursor(newfc, ["SHAPE@"])
array = arcpy.Array()
for point in fileinput.input(infile):
if ":" in point:
x, y = string.strip().split(":")
array.add(arcpy.Point(x, y))
cursor.insertRow([arcpy.Point(array)])
fileinput.close()
del cursor

 

I get the following error:
Traceback (most recent call last):
File "P:/GEOG - Programming in GIS/XYToPoint_Practice.py", line 18, in <module>
cursor.insertRow([arcpy.Point(array)])
File "P:\ArcMap\Desktop10.7\ArcPy\arcpy\arcobjects\mixins.py", line 1122, in __init__
setattr(self, attr, value)
File "P:\ArcMap\Desktop10.7\ArcPy\arcpy\arcobjects\_base.py", line 89, in _set
return setattr(self._arc_object, attr_name, cval(val))
RuntimeError: Point: Input value is not numeric

Attachments

Outcomes