-2

I am trying to create a polygon from a text file that contains latitude and longitude values.

Here is what I have so far:

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 

The Error is:

File line 39
point.Name, point.X, point.Y = line.split()
ValueError: too many values to unpack

Let me know if you need more information.

Here is a screenshot of what the text file looks like:

enter image description here

wim
  • 338,267
  • 99
  • 616
  • 750
LMA
  • 9
  • 3
  • look at the content of the line. it should only contain 3 values separated by a single space – njzk2 Apr 25 '16 at 20:49

1 Answers1

1

You're calling:

line.split()

Which splits on whitespace, by default. The names in your data like "Jones Tract" have whitespace in them.

You probably wanted to split on , character instead, or load with the csv module. Something like this:

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
wim
  • 338,267
  • 99
  • 616
  • 750