2013-10-03 71 views
4

我正在編寫一個python代碼來讀取多邊形形狀文件中的點並將它們保存在點形狀文件中。 所以首先我創建了一個文本文件並將這些點('x')存儲在該.txt文件中。然後我試圖從文本文件中創建一個點形狀文件,但它給出了一個錯誤。
這裏是代碼(只是最後一部分):Python:如何從文本文件創建點形狀文件

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, ["[email protected]"]) 
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 
+0

沒有給予什麼錯誤的文字到底是什麼? –

+0

如果您發佈到地理信息系統,您可能會在此問題上獲得更多的牽引力... http://gis.stackexchange.com – bcollins

+0

謝謝,我做到了。 – user2841098

回答