Skip to content

Commit

Permalink
fix: feature iterator, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
habibutsu committed Apr 17, 2024
1 parent af42285 commit 4e6c0a9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 5 additions & 1 deletion gdal_boots/gdal.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,10 @@ def __init__(self, ds: gdal.Dataset, layer: ogr.Layer):
def __len__(self) -> int:
return self.ref_layer.GetFeatureCount()

def __iter__(self):
for feature in self.ref_layer:
yield Feature(self.ref_ds, feature)

@property
def size(self):
return len(self)
Expand Down Expand Up @@ -1275,7 +1279,7 @@ def union(self, other):
pass

def __del__(self):
if type(self.ds) == ogr.DataSource:
if type(self.ds) is ogr.DataSource:
self.ds.Destroy()
self.ds = None
if self._mem_id:
Expand Down
24 changes: 22 additions & 2 deletions tests/test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,28 @@ def test_read_from_bytes(minsk_boundary_gpkg):
with open(minsk_boundary_gpkg, "rb") as fd:
data = fd.read()

ds = VectorDataset.from_bytes(data)
assert len(ds.layers) == 5
vds = VectorDataset.from_bytes(data)
assert len(vds.layers) == 5

layer = vds.layers.first()

count = 0
for feature in layer.features:
assert feature.keys() == [
"osm_id",
"name",
"barrier",
"highway",
"ref",
"address",
"is_in",
"place",
"man_made",
"other_tags",
]
count += 1

assert count == 7


@pytest.mark.skipif(
Expand Down

0 comments on commit 4e6c0a9

Please sign in to comment.