From ad54abf02c60fac113554aa0baed7cc3640acceb Mon Sep 17 00:00:00 2001 From: Daniel Baston Date: Tue, 30 Apr 2024 20:49:06 -0400 Subject: [PATCH] Python: Allow a FeatureSource to be used multiple times --- python/src/pybindings/feature_source_bindings.cpp | 1 + python/tests/test_feature_source.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/python/src/pybindings/feature_source_bindings.cpp b/python/src/pybindings/feature_source_bindings.cpp index 32341da6..933feb35 100644 --- a/python/src/pybindings/feature_source_bindings.cpp +++ b/python/src/pybindings/feature_source_bindings.cpp @@ -38,6 +38,7 @@ class PyFeatureSourceBase : public FeatureSource auto iter = py::iter(m_it); if (iter == py::iterator::sentinel()) { + m_initialized = false; return false; } m_feature = py::cast(*iter); diff --git a/python/tests/test_feature_source.py b/python/tests/test_feature_source.py index 0202c39a..d6df56f6 100644 --- a/python/tests/test_feature_source.py +++ b/python/tests/test_feature_source.py @@ -22,6 +22,7 @@ def test_gdal_feature_source(): fs = GDALFeatureSource(lyr) assert fs.count() == 5 + assert fs.count() == 5 # make sure we can iterate twice def test_python_feature_source(): @@ -39,3 +40,4 @@ def test_python_feature_source(): fs = JSONFeatureSource(features) assert fs.count() == 5 + assert fs.count() == 5