Closed stuckyb closed 2 years ago
And here is a very simple shapefile for use with the above example: shapefile_pnt-no_crs-no_dir.zip.
One more piece of information. I just now tried running the above code with Python 3.10.4, and it appears to work as expected. This would strongly suggest (to me, anyway), that it is/was a problem with Python's zipfile
library. So perhaps this is a non-issue with more recent Python releases. I'll leave this issue open in case any project maintainers would like to take a look.
Glad you're enjoying the library. I'm not able to dive too deep into the issue, but it does seem be a bug with the zipfile.Path which indeed was fixed in Python 3.10: https://bugs.python.org/issue40564. The bug seems to be that zipfile.Path closes the zipfile prematurely, after which trying to read the shapefile from the shapefile fails, althought there's probably more details to it than that. .
This is such a weird bug I'm hesitant to even open an issue, but here goes. In words: When attempting to read a shapefile from a ZIP archive by manually providing the
shp
anddbf
file-like objects, if azipfile.Path
object is created that references a non-existent item in the ZIP archive, and this is all done from within a function, subsequent attempts to read the shapefile throw aValueError: seek of closed file
exception.Here is minimal code to trigger the bug (I will also upload a simple shapefile to use with this example):
Key points:
ValueError: seek of closed file
.prj_path
is defined) is commented out, everything works as expected. (The ZIP archive does not actually contain a.prj
file.)print()
statement within the function is uncommented, it works even if line 7 is enabled.print(read())
statements near the bottom are uncommented, they produce the same results regardless of whether line 7 is enabled.I am honestly not certain whether this is a bug with shapefile or Python's zipfile library, but key point 4, above, makes me think that pyproj is involved somehow.
Defining a
zipfile.Path
object that references a non-existent file might seem pointless, but it is one way to test whether a file (.prj
file, e.g.) actually exists in an archive.And I wanted to be sure to also thank you for providing this outstanding library!