Skip to content

Commit

Permalink
BUG: Enable mask & bbox filter when geometry column not read
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Jun 24, 2024
1 parent af292e5 commit 69ae70e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyogrio/_io.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions pyogrio/tests/test_raw_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 69ae70e

Please sign in to comment.