Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ Selectively reading only the necessary data in this way is particularly useful f

### Spatial filtering

Another common use-case is that we only want to read those records that are located in some region of interest. Because the shapefile stores the bounding box of each shape separately from the geometry data, it's possible to quickly retrieve all shapes that might overlap a given bounding box region without having to load the full shape geometry data for every shape. This can be done by specifying the `bbox` argument to any of the record or shape methods:
Another common use-case is that we only want to read those records that are located in some region of interest. Because the shapefile stores the bounding box of each shape separately from the geometry data, it's possible to quickly retrieve all shapes that might overlap a given bounding box region without having to load the full shape geometry data for every shape. This can be done by specifying the `bbox` argument to the shapes, iterShapes, or iterShapeRecords methods:


>>> bbox = [36.423, 12.360, 43.123, 18.004] # ca bbox of Eritrea
Expand Down
7 changes: 7 additions & 0 deletions shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,13 @@ def __shape(self, oid=None, bbox=None):
# Read a single point
if shapeType in (1,11,21):
record.points = [_Array('d', unpack("<2d", f.read(16)))]
if bbox is not None:
# create bounding box for Point by duplicating coordinates
point_bbox = list(record.points[0] + record.points[0])
# skip shape if no overlap with bounding box
if not bbox_overlap(bbox, point_bbox):
f.seek(next)
return None
# Read a single Z value
if shapeType == 11:
record.z = list(unpack("<d", f.read(8)))
Expand Down