Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import array
import tempfile
import itertools
import io
from datetime import date

#
Expand Down Expand Up @@ -238,23 +239,35 @@ def __init__(self, *args, **kwargs):
if "shp" in kwargs.keys():
if hasattr(kwargs["shp"], "read"):
self.shp = kwargs["shp"]
if hasattr(self.shp, "seek"):
# Copy if required
try:
self.shp.seek(0)
except (NameError, io.UnsupportedOperation):
self.shp = io.BytesIO(self.shp.read())
if "shx" in kwargs.keys():
if hasattr(kwargs["shx"], "read"):
self.shx = kwargs["shx"]
if hasattr(self.shx, "seek"):
# Copy if required
try:
self.shx.seek(0)
except (NameError, io.UnsupportedOperation):
self.shx = io.BytesIO(self.shx.read())
if "dbf" in kwargs.keys():
if hasattr(kwargs["dbf"], "read"):
self.dbf = kwargs["dbf"]
if hasattr(self.dbf, "seek"):
# Copy if required
try:
self.dbf.seek(0)
except (NameError, io.UnsupportedOperation):
self.dbf = io.BytesIO(self.dbf.read())
if self.shp or self.dbf:
self.load()
else:
raise ShapefileException("Shapefile Reader requires a shapefile or file-like object.")




def load(self, shapefile=None):
"""Opens a shapefile from a filename or file-like
object. Normally this method would be called by the
Expand Down