Skip to content

Commit 63e734c

Browse files
authored
BUG: Enable mask & bbox filter when geometry column not read (#431)
1 parent d82974c commit 63e734c

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Bug fixes
66

77
- Silence warning from `write_dataframe` with `GeoSeries.notna()` (#435).
8+
- BUG: Enable mask & bbox filter when geometry column not read (#431).
89

910
## 0.9.0 (2024-06-17)
1011

pyogrio/_io.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ def ogr_read(
12741274
idx = np.intersect1d(fields[:,2], columns, return_indices=True)[1]
12751275
fields = fields[idx, :]
12761276

1277-
if not read_geometry:
1277+
if not read_geometry and bbox is None and mask is None:
12781278
ignored_fields.append("OGR_GEOMETRY")
12791279

12801280
# Instruct GDAL to ignore reading fields not

pyogrio/tests/test_raw_io.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,31 @@ def test_read_no_geometry(naturalearth_lowres):
116116
assert geometry is None
117117

118118

119+
@pytest.mark.skipif(
120+
not HAS_SHAPELY, reason="Shapely is required for mask functionality"
121+
)
122+
def test_read_no_geometry__mask(naturalearth_lowres):
123+
geometry, fields = read(
124+
naturalearth_lowres,
125+
read_geometry=False,
126+
mask=shapely.Point(-105, 55),
127+
)[2:]
128+
129+
assert np.array_equal(fields[3], ["CAN"])
130+
assert geometry is None
131+
132+
133+
def test_read_no_geometry__bbox(naturalearth_lowres):
134+
geometry, fields = read(
135+
naturalearth_lowres,
136+
read_geometry=False,
137+
bbox=(-109.0, 55.0, -109.0, 55.0),
138+
)[2:]
139+
140+
assert np.array_equal(fields[3], ["CAN"])
141+
assert geometry is None
142+
143+
119144
def test_read_no_geometry_no_columns_no_fids(naturalearth_lowres):
120145
with pytest.raises(
121146
ValueError,

0 commit comments

Comments
 (0)