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 Jul 2, 2024
1 parent 33d32ec commit d9ea20f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# CHANGELOG

## 0.9.1 (2024-??-??)

### Improvements


### Bug fixes

- BUG: Enable mask & bbox filter when geometry column not read (#431).

### Packaging


## 0.9.0 (2024-06-17)

### Improvements
Expand Down
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 d9ea20f

Please sign in to comment.