Make features iterator reset next feature pointer
MODIFY
src/vector/layer.rs
src/vector/layer.rs
@@ -84,6 +84,7 @@ impl<'a> Layer<'a> {
/// Iterate over all features in this layer.
pub fn features(&mut self) -> FeatureIterator {
+ self.reset_feature_reading();
FeatureIterator::_with_layer(self)
}
@@ -241,6 +242,12 @@ impl<'a> Layer<'a> {
}
SpatialRef::from_c_obj(c_obj)
}
+
+ fn reset_feature_reading(&mut self) {
+ unsafe {
+ gdal_sys::OGR_L_ResetReading(self.c_layer);
+ }
+ }
}
pub struct FeatureIterator<'a> {

MODIFY
src/vector/vector_tests/mod.rs
src/vector/vector_tests/mod.rs
@@ -492,6 +492,17 @@ mod tests {
assert_eq!(ft.field("Int_value").unwrap().unwrap().into_int(), Some(1));
}
+ #[test]
+ fn test_features_reset() {
+ with_layer("roads.geojson", |mut layer| {
+ assert_eq!(
+ layer.features().count(),
+ layer.features().count(),
+ );
+ });
+
+ }
+
// A compilation test that should fail.
//
// It tries to iterate over a layer's features, while

Make features iterator reset next feature pointer