GeospatialPython / pyshp

This library reads and writes ESRI Shapefiles in pure Python.
MIT License
1.1k stars 259 forks source link

Support for reading standalone dbf files #126

Closed gastoneb closed 6 years ago

gastoneb commented 6 years ago

Hi, I'm trying to load a standalone dbf file (i.e. there is no *.shp file, just the table). However, the Reader.load() function requires that both the dbf and shp files exist. Can we change the "and" on line 376 to "or" in the next release?

if not (self.shp and self.dbf):
    raise ShapefileException("Unable to open %s.dbf or %s.shp." % (shapeName, shapeName) )
GeospatialPython commented 6 years ago

This is a good idea. We should be able to use any of the files separately.

There is a workaround in the meantime however if you pass the dbf in as a file handle:

import shapefile
f = open("my_shape.dbf", "rb")
r = shapefile.Reader(dbf=f)
r.record(0) # lists the values of the first record