Error in shapes()
Closed this issue · 2 comments
Hi.
The issue occurs when I call shapes method:
ERROR : [Errno 22] Invalid argument
...
shapes.append(self.__shape())
File ".../site-packages/shapefile.py", line 1106, in __shape
f.seek(next)
the code is below:
`
mydbf = open("./my.dbf", "rb")
myshp = open("./my.shp", "rb")
r = shapefile.Reader(shp=myshp, dbf=mydbf, encoding='iso-8859-1')
shapes = r.shapes()
`
then I modify the shapefile as below:
def __shape(self): ... try: f.seek(next) except: ...
finally I found the problem is because the 2 files(dbf, shp)sizes are inconsistent!
Could you report which version of pyshp you are using, and/or provide the shapefile if possible?
I suspect this is a malformed shapefile, which would also make sense if you found that the dbf and shp sizes were inconsistent. Looking at the source code of the shapes()
method, it first determines the total length of the file, and while the current file position is less than the file length, it calls the __shape()
method which determines how much to read of each shape. Therefore, the only way it could seek beyond the end of the file is if the __shape()
method reads too much at the end of the file.
The length of each shape is stored in the file itself in the header of each shape, and is how the __shape()
method determines the length of each shape. So either the shapefile was created with an incorrect shape length for a particular shape (such that it extended beyond the file length), or the shapefile is corrupted/incomplete, eg if the software that created the shapefile was terminated before it could complete.
Should be fixed in v2.3.0. See #235.