-2

Traceback (most recent call last): File "C:\Users\Brett\Desktop\Jefferson_final.py", line 31, in point = arcpy.Point(coordinate[0],coordinate[1]) IndexError: list index out of range

Here is my script

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 Answers1

2

You are not opening the file input_data and reading the input data from it then splitting the data.

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

Should get you further - you will also have to convert x & y to numeric values they will be strings to start with.

Steve Barnes
  • 27,618
  • 6
  • 63
  • 73