emare / pyshp

Automatically exported from code.google.com/p/pyshp
MIT License
0 stars 0 forks source link

Polygons cannot be built using tuple points #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
If the Python `zip` function is used to combine X and Y coordinates, the result 
is a list of tuples:

X = [1, 5, 5, 3, 1]
Y = [5, 5, 1, 3, 1]
coors = zip(X, Y) # list of tuples

However, this object cannot be used by the shapefile.py module:

import shapefile
w = shapefile.Writer(shapefile.POLYGON)
w.field('MYFIELD','C')
w.poly([coors])
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "shapefile.py", line 684, in poly
    point.append(0)
AttributeError: 'tuple' object has no attribute 'append'

To fix this, I've added a check to shapefile.py near line 679:
# Ensure point is list
if not isinstance(point, list):
        point = list(point)

See attached patch. I've also removed trailing whitespace on various lines in 
this patch.

Original issue reported on code.google.com by mwto...@gmail.com on 3 Mar 2011 at 12:04

Attachments:

GoogleCodeExporter commented 8 years ago
Another similar patch for the Python3 branch

Original comment by mwto...@gmail.com on 5 Mar 2011 at 5:45

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by geospati...@gmail.com on 17 Nov 2011 at 3:20