8000 Add method `iterRecords_range` by lguez · Pull Request #309 · GeospatialPython/pyshp · GitHub
[go: up one dir, main page]

Skip to content

Add method iterRecords_range #309

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

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
Next Next commit
Add option my_range to method iterRecords
Using iterRecords with a range option should be faster than calling
record within a loop, since we avoid the multiple calls to seek.
  • Loading branch information
lguez committed Oct 11, 2024
commit e41b03ca574ed79c58bad9dc9e72d84dc98af19b
6 changes: 4 additions & 2 deletions shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,7 @@ def records(self, fields=None):
records.append(r)
return records

def iterRecords(self, fields=None):
def iterRecords(self, fields=None, my_range=None):
"""Returns a generator of records in a dbf file.
Useful for large shapefiles or dbf files.
To only read some of the fields, specify the 'fields' arg as a
Expand All @@ -1820,7 +1820,9 @@ def iterRecords(self, fields=None):
f = self.__getFileObj(self.dbf)
f.seek(self.__dbfHdrLength)
fieldTuples, recLookup, recStruct = self.__recordFields(fields)
for i in xrange(self.numRecords):
if my_range is None:
my_range = xrange(self.numRecords)
for i in my_range:
r = self.__record(
oid=i, fieldTuples=fieldTuples, recLookup=recLookup, recStruct=recStruct
)
Expand Down
Loading
0