[Tutor] Issue with a shapefile (ArcGIS) library (pyshp) "unpack requires a string argument of length 8"

Simeon Tesfaye Simeon.Tesfaye at eaudeparis.fr
Fri Feb 3 16:46:13 CET 2012


Hello everyone,
 
I am having a bit of trouble here with my code, which uses a shapefile library, named pyshp, to import, edit, and save GIS files within Python.
So, I open up my shapefile (data is polylines, meaning, not points or polygons)
"shapefile=shapefile.Reader("file.shp")
shps=shapefile.shapes()
shprec = shapefile.records()
"
Then I carry out some edits, and I save my file.
When I want to open it again, within the same script, in order to access some of the data I just modified, I get this message :
 
"Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    troncop=troncon.shapes()
  File "C:\Python25\Lib\shapefile.py", line 310, in shapes
    while shp.tell() < self.shpLength:
  File "C:\Python25\Lib\shapefile.py", line 222, in __shape
    print(f.read(8))
  File "C:\Python25\lib\struct.py", line 87, in unpack
    return o.unpack(s)
error: unpack requires a string argument of length 8"
 
 
I reckon this part tries to import header information for shape data, which would be stored in C (?), and fails to "unpack" it in PYTHON.
 
I've tried putting an "IF" to check whether f.read(8) was actually a string (type) and of length equal to 8. I still get the same error message.
I've also tried skipping the "unpack" part altogther, not with much success.
 
I'm really not too familiar with Python, si if anyone could help me out with this, I'd be really grateful.
 
Thanks in advance,
 
S.T.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120203/6599e6cf/attachment.html>


More information about the Tutor mailing list