我正在尝试从包含纬度和经度值的文本文件创建多边形。
这是我到目前为止所做的:
out_path ="C:/Output"
out_name = "Shapefile.shp"
geometry_type = "POLYGON"
template = "Other.shp"
has_m = "DISABLED"
has_z = "DISABLED"
spatial_reference = arcpy.Describe("Other.shp").spatialReference
arcpy.CreateFeatureclass_management(out_path, out_name, geometry_type, template, has_m, has_z, spatial_reference)
cursor = arcpy.da.InsertCursor("Other.shp", ["SHAPE@"])
array = arcpy.Array()
point = arcpy.Point()
for line in fileinput.input(new_txt):
point.Name, point.X, point.Y = line.split()
line_array.add(point)
polygon = arcpy.Polygon(array)
cursor.insertRow([polygon])
fileinput.close()
del cursor
错误是:
File line 39
point.Name, point.X, point.Y = line.split()
ValueError: too many values to unpack
如果您需要更多信息,请与我们联系。
以下是文本文件的截图:
答案 0 :(得分:1)
您正在致电:
line.split()
默认情况下,哪个在空格上分割。数据中的名称,如" Jones Tract"他们有空白。
您可能希望拆分,
字符,或者使用csv
模块加载。像这样:
column_types = unicode, float, float, int
row = (f(v) for f,v in zip(column_types, line.split(',')))
point.Name, point.X, point.Y, other_thing = row