I'm writing a python code to read the points in a polygon shape-file and save them in a point shape file. So first I made a text file and stored the points' (x,y) in that .txt file. then I tried to make a point shape-file from the text file but it gave an error.
here is the code (just the last part):
我正在编写一个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
Here is the error:
这是错误:
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
1 个解决方案
#1
1
have you tried calling float(X), float(Y) as maybe its doesn't like strings?
您是否尝试过调用float(X)、float(Y),因为它可能不喜欢字符串?
If you can get your input into a numpy array, you can convert that to a feature class in one step:
如果您可以将您的输入输入到一个numpy数组中,您可以在一个步骤中将其转换为一个特性类:
http://arcpy.wordpress.com/2012/09/14/building-feature-classes-from-numpy-arrays/
http://arcpy.wordpress.com/2012/09/14/building-feature-classes-from-numpy-arrays/
#1
1
have you tried calling float(X), float(Y) as maybe its doesn't like strings?
您是否尝试过调用float(X)、float(Y),因为它可能不喜欢字符串?
If you can get your input into a numpy array, you can convert that to a feature class in one step:
如果您可以将您的输入输入到一个numpy数组中,您可以在一个步骤中将其转换为一个特性类:
http://arcpy.wordpress.com/2012/09/14/building-feature-classes-from-numpy-arrays/
http://arcpy.wordpress.com/2012/09/14/building-feature-classes-from-numpy-arrays/