Skip to content

Commit

Permalink
Merge #209
Browse files Browse the repository at this point in the history
209: set_attribute_filter shouild take &mut self r=lnicola a=jdroenner

- [x] I agree to follow the project's [code of conduct](https://github.com/georust/gdal/blob/master/CODE_OF_CONDUCT.md).
- [x] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
---

set_attribute_filter should take &mut self since OGR_L_SetAttributeFilter resets the reading position. 

Co-authored-by: Johannes Drönner <[email protected]>
Co-authored-by: Johannes Drönner <[email protected]>
  • Loading branch information
3 people authored Aug 6, 2021
2 parents 6a34a69 + 78c88e3 commit 9182b76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- **Breaking**: Make `set_attribute_filter` and `clear_attribute_filter` take `&mut self`
- <https://github.com/georust/gdal/pull/209/>

- **Breaking**: Drop pre-build bindings for GDAL versions < 2.4. The bindgen feature can be used to generate bindings for older versions.
- Fix memory leaks reported by Valgrind. This required re-generation of the pre-build bindings.
- <https://github.com/georust/gdal/pull/205>
Expand Down
9 changes: 7 additions & 2 deletions src/vector/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,12 @@ impl<'a> Layer<'a> {

/// Set a new attribute query that restricts features when using the feature iterator.
///
/// From the GDAL docs: Note that installing a query string will generally result in resetting the current reading position
///
/// Parameters:
/// - `query` in restricted SQL WHERE format
///
pub fn set_attribute_filter(&self, query: &str) -> Result<()> {
pub fn set_attribute_filter(&mut self, query: &str) -> Result<()> {
let c_str = CString::new(query)?;
let rv = unsafe { gdal_sys::OGR_L_SetAttributeFilter(self.c_layer, c_str.as_ptr()) };

Expand All @@ -357,7 +359,10 @@ impl<'a> Layer<'a> {
}

/// Clear the attribute filter set on this layer
pub fn clear_attribute_filter(&self) {
///
/// From the GDAL docs: Note that installing a query string will generally result in resetting the current reading position
///
pub fn clear_attribute_filter(&mut self) {
unsafe {
gdal_sys::OGR_L_SetAttributeFilter(self.c_layer, null_mut());
}
Expand Down

0 comments on commit 9182b76

Please sign in to comment.