I am trying to write a script that creates a new polygon feature class containing a single ( square ) polygon with the following coordinates: ( 0, 0 ), ( 0, 1,000 ), ( 1,000, 0 ), and ( 1,000, 1,000 ).
import arcpy
import fileinput
import string
import os
from arcpy import env
env.workspace = "D:/UW/Winter_2016/501/w5_more_arcpy8_9_10/ex8"
env.overwriteOutput = True
infile = "D:/UW/Winter_2016/501/w5_more_arcpy8_9_10/ex8/coordinatesEx8.txt"
for line in fileinput.FileInput(infile):
ID, X, Y = string.split(line, " ")
array.add(arcpy.Point(X, Y))
cursor.insertRow([arcpy.Polygon(array)])
fileinput.close()
outpath = "D:/UW/Winter_2016/501/w5_more_arcpy8_9_10/ex8"
newfc = "newFeatureClassEx8.shp"
arcpy.CreateFeatureclass_management(outpath, newfc, "Polygon")
cursor = arcpy.da.InsertCursor(newfc, ["SHAPE@"])
array = arcpy.Array()
del cursor
coordinatesEx8.txt looks like this below
1 0 1000
2 1000 0
3 1000 1000
4 0 0
Hanging up on this line:
for line in fileinput.FileInput(infile):
Error message:
ValueError: too many values to unpack
any suggestions? I'm at a loss, I thought it was the set up of my .txt file but keeps hanging on that error no matter what. Not sure how to proceed, this is the question before my actual homework question which will be much harder...also originally the for loop was:
for line in fileinput.input(infile):
which gave a different error...