我正在编写一个 python 代码来读取多边形形状文件中的点并将它们保存在一个点形状文件中。所以首先我制作了一个文本文件并将点 (x,y) 存储在该 .txt 文件中。然后我试图从文本文件中创建一个点形状文件,但它给出了一个错误。
这是代码(只是最后一部分):
creat point shape-file from text file
import fileinput
import string
import os
env.overwriteOutput=True
outpath="C:/roadpl"
newfc="newpoint.shp"
arcpy.CreateFeatureclass_management(outpath, newfc, "Point")
infile="C:/roadpl/roadL5.txt"
cursor=arcpy.da.InsertCursor(newfc, ["SHAPE@"])
array=arcpy.Array()
for line in fileinput.input(infile):
X, Y=string.split(line, " ")
array.add(arcpy.Point(X,Y))
cursor.insertRow([arcpy.Point(array)])
fileinput.close()
del cursor
这是错误:
Traceback (most recent call last):
File "C:\Lab5\P_Code_L5", line 49, in <module>
point.X, point.Y = line.split()
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\_base.py", line 87, in _set
return setattr(self._arc_object, attr_name, cval(val))
RuntimeError: Point: Input value is not numeric