Skip to content

Commit 9d31036

Browse files
committed
bbox filtering for single points
1 parent d3b6e2a commit 9d31036

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ Selectively reading only the necessary data in this way is particularly useful f
12241224

12251225
### Spatial filtering
12261226

1227-
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:
1227+
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:
12281228

12291229

12301230
>>> bbox = [36.423, 12.360, 43.123, 18.004] # ca bbox of Eritrea

shapefile.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,12 @@ def __shape(self, oid=None, bbox=None):
13601360
# Read a single point
13611361
if shapeType in (1,11,21):
13621362
record.points = [_Array('d', unpack("<2d", f.read(16)))]
1363+
# create bounding box for Point by duplicating coordinates
1364+
point_bbox = list(record.points[0] + record.points[0])
1365+
# skip shape if no overlap with bounding box
1366+
if not bbox_overlap(bbox, point_bbox):
1367+
f.seek(next)
1368+
return None
13631369
# Read a single Z value
13641370
if shapeType == 11:
13651371
record.z = list(unpack("<d", f.read(8)))

0 commit comments

Comments
 (0)