我试图从txt创建x,y坐标的ashape文件。文件,但我收到以下错误

时间:2016-08-09 06:23:01

标签: python arcpy arcmap

追踪(最近一次通话):   文件" C:\ Users \ Brett \ Desktop \ Jefferson_final.py",第31行,在     point = arcpy.Point(坐标[0],坐标[1]) IndexError:列表索引超出范围

这是我的剧本

import arcpy
import fileinput
import os
import string
arcpy.env.workspace = "C:\Users\Brett\Desktop\San Clemente"
arcpy.env.overwriteOutput = True

outFolder = "C:\Users\Brett\Desktop\San Clemente"
output = open("result.txt", "w")
fc = "metersSC1.shp"
inputFile = "C:\Users\Brett\Desktop\San Clemente\San Clemente Lat Long.txt"
name = ""

for line in inputFile:
    lineSegment = line.split(": ")
   if lineSegment[0]== "spatialReference":
        spatRef = spatRef = arcpy.SpatialReference(26946)
        arcpy.CreateFeatureclass_management(outFolder, fc, "POINT", "", "", "", spatRef)
    arcpy.AddField_management(fc, "NAME", "TEXT")
    cursor = arcpy.da.InsertCursor(fc, ["","SHAPE@"])
    array = arcpy.Array()
elif lineSegment[0] =="NAME":
    if len(array) > 0:
        polygon = arcpy.Polygon(pointList)
        cursor.insertRow((name,polygon))

        name = lineSegment[0]

else:
    coordinate = line.split(",")
    point = arcpy.Point(coordinate[0],coordinate[1])
    pointList.add(point)



polygon = arcpy.Polygon(array)
cursor.insertRow((name, polygon))

print "COORDINATES ADDED"

1 个答案:

答案 0 :(得分:2)

您没有打开文件input_data并从中读取输入数据然后拆分数据。

inputname = r"C:\Users\Brett\Desktop\San Clemente\San Clemente Lat Long.txt"
inputdata = [l.spilt(',') for l in open(inputname).readlines()]

应该让你更进一步 - 你还必须转换x& y为数值,它们将是字符串开头。