diff --git a/CHANGES.md b/CHANGES.md index 2eca8d48..786762c9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ ### Bug fixes - Silence warning from `write_dataframe` with `GeoSeries.notna()` (#435). +- BUG: Enable mask & bbox filter when geometry column not read (#431). ## 0.9.0 (2024-06-17) diff --git a/pyogrio/_io.pyx b/pyogrio/_io.pyx index 8487c728..7c6427ce 100644 --- a/pyogrio/_io.pyx +++ b/pyogrio/_io.pyx @@ -1274,7 +1274,7 @@ def ogr_read( idx = np.intersect1d(fields[:,2], columns, return_indices=True)[1] fields = fields[idx, :] - if not read_geometry: + if not read_geometry and bbox is None and mask is None: ignored_fields.append("OGR_GEOMETRY") # Instruct GDAL to ignore reading fields not diff --git a/pyogrio/tests/test_raw_io.py b/pyogrio/tests/test_raw_io.py index e21f768c..ebabe073 100644 --- a/pyogrio/tests/test_raw_io.py +++ b/pyogrio/tests/test_raw_io.py @@ -116,6 +116,31 @@ def test_read_no_geometry(naturalearth_lowres): assert geometry is None +@pytest.mark.skipif( + not HAS_SHAPELY, reason="Shapely is required for mask functionality" +) +def test_read_no_geometry__mask(naturalearth_lowres): + geometry, fields = read( + naturalearth_lowres, + read_geometry=False, + mask=shapely.Point(-105, 55), + )[2:] + + assert np.array_equal(fields[3], ["CAN"]) + assert geometry is None + + +def test_read_no_geometry__bbox(naturalearth_lowres): + geometry, fields = read( + naturalearth_lowres, + read_geometry=False, + bbox=(-109.0, 55.0, -109.0, 55.0), + )[2:] + + assert np.array_equal(fields[3], ["CAN"]) + assert geometry is None + + def test_read_no_geometry_no_columns_no_fids(naturalearth_lowres): with pytest.raises( ValueError,