Skip to content

Commit

Permalink
Add Feature::unset_field
Browse files Browse the repository at this point in the history
lnicola committed Dec 23, 2023
1 parent aebb751 commit f435e40
Showing 2 changed files with 34 additions and 4 deletions.
11 changes: 7 additions & 4 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -2,11 +2,14 @@

## Unreleased

- Added ability to convert between `Buffer<T>` and `ndarray::Array2<T>`.
- Implemented `IntoIterator`, `Index` and `IndexMut` for `Buffer<T>`.
- Added `Feature::unset_field`
- <https://github.com/georust/gdal/pull/503>

- Added ability to convert between `Buffer<T>` and `ndarray::Array2<T>`.
- Implemented `IntoIterator`, `Index` and `IndexMut` for `Buffer<T>`.
- **Breaking**: `Buffer<T>::size` is now private and accessed via `Buffer<T>::shape().
- **Breaking**: `Buffer<T>::data` is now private and accessed via `Buffer<T>::data().
- **Breaking**: Removed `Rasterband::read_as_array`, changed signature of `Rasterband::read_block` to return a `Buffer<T>`.
- **Breaking**: `Buffer<T>::data` is now private and accessed via `Buffer<T>::data().
- **Breaking**: Removed `Rasterband::read_as_array`, changed signature of `Rasterband::read_block` to return a `Buffer<T>`.
- **Breaking**: `Rasterband::write` and `Rasterband::write_block` now require a `&mut Buffer<T>` to handle possible case of drivers temporarily mutating input buffer.

- <https://github.com/georust/gdal/pull/494>
27 changes: 27 additions & 0 deletions src/vector/feature.rs
Original file line number Diff line number Diff line change
@@ -648,12 +648,28 @@ impl<'a> Feature<'a> {
}
}

/// Clear a field, marking it as null.
///
/// See: [`OGRFeature::SetFieldNull`][SetFieldNull]
///
/// [SetFieldNull]: https://gdal.org/api/ogrfeature_cpp.html#_CPPv4N10OGRFeature12SetFieldNullEi
pub fn set_field_null(&self, field_name: &str) -> Result<()> {
let idx = self.field_idx_from_name(field_name)?;
unsafe { gdal_sys::OGR_F_SetFieldNull(self.c_feature(), idx) };
Ok(())
}

/// Clear a field, marking it as unset.
///
/// See: [`OGRFeature::UnsetField`][UnsetField]
///
/// [UnsetField]: https://gdal.org/api/ogrfeature_cpp.html#_CPPv4N10OGRFeature10UnsetFieldEi
pub fn unset_field(&self, field_name: &str) -> Result<()> {
let idx = self.field_idx_from_name(field_name)?;
unsafe { gdal_sys::OGR_F_UnsetField(self.c_feature(), idx) };
Ok(())
}

pub fn set_geometry(&mut self, geom: Geometry) -> Result<()> {
let rv = unsafe { gdal_sys::OGR_F_SetGeometry(self.c_feature, geom.c_geometry()) };
if rv != OGRErr::OGRERR_NONE {
@@ -943,4 +959,15 @@ mod tests {
}
}
}

#[test]
fn test_field_unset() {
let ds = Dataset::open(fixture("roads.geojson")).unwrap();

let mut layer = ds.layers().next().expect("layer");
let feature = layer.features().next().expect("feature");
for (field_name, _) in feature.fields() {
feature.unset_field(&field_name).unwrap();
}
}
}

0 comments on commit f435e40

Please sign in to comment.