diff --git a/CHANGES.md b/CHANGES.md index 43f02f3e..23e64bde 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ - Add a `bundled` feature for `gdal-sys` that allows to build and statically link a minimal bundled version of gdal during `cargo build` - Add methods ``alternative_name``, ``is_nullable``, ``is_unique``, ``default_value`` to ``Field``. - Add a `geometry_type` method to Layer.defn +- Upgraded `ndarray` dependency to 0.16. ## 0.17.1 diff --git a/Cargo.toml b/Cargo.toml index 76d5b788..b2374277 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ libc = "0.2" geo-types = { version = "0.7.11" } gdal-sys = { path = "gdal-sys", version = "0.10" } gdal-src = { path = "gdal-src", optional = true, default-features = false } -ndarray = { version = "0.15", optional = true } +ndarray = { version = "0.16", optional = true } chrono = { version = "0.4.26", default-features = false } bitflags = "2.4" once_cell = "1.18" diff --git a/src/raster/buffer.rs b/src/raster/buffer.rs index 9bc7ac47..c667b68c 100644 --- a/src/raster/buffer.rs +++ b/src/raster/buffer.rs @@ -220,7 +220,11 @@ impl From> for Buffer { let shape = value.shape(); let (cols, rows) = (shape[1], shape[0]); let data: Vec = if value.is_standard_layout() { - value.into_raw_vec() + let (data, offset) = value.into_raw_vec_and_offset(); + match offset { + None | Some(0) => data, + Some(offset) => data[offset..].to_vec(), + } } else { value.iter().copied().collect() }; @@ -233,7 +237,7 @@ impl From> for Buffer { #[cfg(test)] mod tests { use crate::raster::Buffer; - use ndarray::{Array2, ShapeBuilder}; + use ndarray::{arr2, s, Array2, ShapeBuilder}; #[test] fn convert_to() { @@ -258,8 +262,8 @@ mod tests { #[test] fn shapes() { - let s1 = (10, 5).into_shape().set_f(true); - let s2 = (10, 5).into_shape().set_f(false); + let s1 = (10, 5).set_f(true); + let s2 = (10, 5).set_f(false); let a1 = Array2::from_shape_fn(s1, |(y, x)| y as i32 * 5 + x as i32); let a2 = Array2::from_shape_fn(s2, |(y, x)| y as i32 * 5 + x as i32); @@ -275,6 +279,17 @@ mod tests { assert_eq!(b2, expected); } + #[test] + fn offset() { + let arr = arr2(&[[0, 1, 2], [10, 11, 12]]); + let slice = arr.slice_move(s![1.., ..]); + + let expected = Buffer::new((3, 1), (10..13).collect()); + let buffer = Buffer::from(slice); + + assert_eq!(buffer, expected); + } + #[test] fn index() { // Tests if there is one-to-one mapping between whole buffer, and whole range of indices