Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method iterRecords_range #309

Closed
wants to merge 3 commits into from
Closed
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
26 changes: 26 additions & 0 deletions shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1827,6 +1827,32 @@ def iterRecords(self, fields=None):
if r:
yield r

def iterRecords_range(self, start, stop, fields=None):
"""Returns a generator of records in a dbf file, for a range
of oid. Useful for large shapefiles or dbf files. To only
read some of the fields, specify the 'fields' arg as a list of
one or more fieldnames.

"""
if self.numRecords is None:
self.__dbfHeader()
f = self.__getFileObj(self.dbf)
start = self.__restrictIndex(start)
if abs(stop) > self.numRecords:
raise IndexError("Record index out of range.")
if stop < 0:
stop = range(self.numRecords)[stop]
recSize = self.__recordLength
f.seek(0)
f.seek(self.__dbfHdrLength + (start * recSize))
fieldTuples, recLookup, recStruct = self.__recordFields(fields)
for i in xrange(start, stop):
r = self.__record(
oid=i, fieldTuples=fieldTuples, recLookup=recLookup, recStruct=recStruct
)
if r:
yield r

def shapeRecord(self, i=0, fields=None, bbox=None):
"""Returns a combination geometry and attribute record for the
supplied record index.
Expand Down
Loading