diff --git a/CHANGES.md b/CHANGES.md index c4dd40e3..e18053bc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,13 +2,15 @@ ## Unreleased -* **Breaking**: Make `Layer::features` iterator reset to +- **Breaking**: Make `Layer::features` iterator reset to beginning, and borrow mutably. - * closes -* **Breaking**: [Enforce borrow + - closes + +- **Breaking**: [Enforce borrow semantics](https://github.com/georust/gdal/pull/161) on methods of `Dataset`, `RasterBand`, and `Layer`. + 1. Methods that do not modify the underlying structure take `&self`. 1. Methods that modify the underlying structure take `&mut self`. @@ -21,42 +23,45 @@ // band needs to be mutable to set no-data value band.set_no_data_value(0.0)?; ``` - -* Implement wrapper for `OGR_L_TestCapability` - * - -* **Breaking**: Use `DatasetOptions` to pass as `Dataset::open_ex` parameters and - add support for extended open flags. - - ```rust - use gdal::{ Dataset, DatasetOptions } - - let dataset = Dataset::open_ex( - "roads.geojson", - DatasetOptions { - open_flags: GdalOpenFlags::GDAL_OF_UPDATE|GdalOpenFlags::GDAL_OF_VECTOR, - ..DatasetOptions::default() - } - ) - .unwrap(); - ``` - - `GDALAccess` values are supported using [`From`] implementation - - ```rust - Dataset::open_ex( - "roads.geojson", - DatasetOptions { - open_flags: GDALAccess::GA_Update.into(), - ..DatasetOptions::default() - }, - ) - .unwrap(); - ``` - -* Add more functions to SpatialRef implementation - * -* **Breaking**: Change `Feature::field` return type from + +- **Breaking**: Upgrade to `ndarray 0.15` + - +- Implement wrapper for `OGR_L_TestCapability` + + - + +- **Breaking**: Use `DatasetOptions` to pass as `Dataset::open_ex` parameters and + add support for extended open flags. + + ```rust + use gdal::{ Dataset, DatasetOptions } + + let dataset = Dataset::open_ex( + "roads.geojson", + DatasetOptions { + open_flags: GdalOpenFlags::GDAL_OF_UPDATE|GdalOpenFlags::GDAL_OF_VECTOR, + ..DatasetOptions::default() + } + ) + .unwrap(); + ``` + + `GDALAccess` values are supported using [`From`] implementation + + ```rust + Dataset::open_ex( + "roads.geojson", + DatasetOptions { + open_flags: GDALAccess::GA_Update.into(), + ..DatasetOptions::default() + }, + ) + .unwrap(); + ``` + +- Add more functions to SpatialRef implementation + - +- **Breaking**: Change `Feature::field` return type from `Result` to `Result>`. Fields can be null. Before this change, if a field was null, the value returned was the default value for the underlying type. @@ -86,93 +91,101 @@ .into_string() .unwrap(); ``` - * -* Fixed potential race condition wrt. GDAL driver initialization - * -* Add basic support to read overviews -* Added a `Dataset::build_overviews` method - * -* BREAKING: update geo-types to 0.7.0. geo-types Coordinate now implement `Debug` - * -* Deprecated `SpatialRef::get_axis_mapping_strategy` - migrate to + + - + +- Fixed potential race condition wrt. GDAL driver initialization + - +- Add basic support to read overviews +- Added a `Dataset::build_overviews` method + - +- BREAKING: update geo-types to 0.7.0. geo-types Coordinate now implement `Debug` + - +- Deprecated `SpatialRef::get_axis_mapping_strategy` - migrate to `SpatialRef::axis_mapping_strategy` instead. -* Add support for reading and setting rasterband colour interpretations - * +- Add support for reading and setting rasterband colour interpretations + - +- Fixed memory leak in `Geometry::from_wkt` + - + ## 0.7.1 -* fix docs.rs build for gdal-sys - * + +- fix docs.rs build for gdal-sys + - ## 0.6.0 - 0.7.0 -* Dataset layer iteration and FieldValue types - * https://github.com/georust/gdal/pull/126 -* Fix i8 ptr instead of c_char ptr passed to OSRImportFromESRI() - * -* Rename spatial_reference to spatial_ref - * -* Replace get_extent force flag by get_extent and try_get_extent - * -* Add support for transactions on datasets - * -* Add feature_count{,_force} and implement Iterator::size_hint - * -* Replace failure with thiserror - * -* Ability to read into preallocated slice for rasterband - * -* Datasets are Send (requires GDAL >= 2.3) - * -* User GDALOpenEx - * -* GDAL 2.0 conform structure / drop GDAL 1.x - * -* Inplace functions use mutable refs - * -* Detect GDAL version at build time / remove version features - * -* Add support for delaunay_triangulation and simplify functions - * -* Add support for 3d points - * -* Additional metadata retrieval options - * -* Support for GDAL 3 in CI - * -* Support for Integer64 - * -* Geometry Intersection trait - * -* Rust 2018 - * -* support for date and time fields - * -* Prebuild bindings - * -* Support for ndarray - * + +- Dataset layer iteration and FieldValue types + - https://github.com/georust/gdal/pull/126 +- Fix i8 ptr instead of c_char ptr passed to OSRImportFromESRI() + - +- Rename spatial_reference to spatial_ref + - +- Replace get_extent force flag by get_extent and try_get_extent + - +- Add support for transactions on datasets + - +- Add feature_count{,\_force} and implement Iterator::size_hint + - +- Replace failure with thiserror + - +- Ability to read into preallocated slice for rasterband + - +- Datasets are Send (requires GDAL >= 2.3) + - +- User GDALOpenEx + - +- GDAL 2.0 conform structure / drop GDAL 1.x + - +- Inplace functions use mutable refs + - +- Detect GDAL version at build time / remove version features + - +- Add support for delaunay_triangulation and simplify functions + - +- Add support for 3d points + - +- Additional metadata retrieval options + - +- Support for GDAL 3 in CI + - +- Support for Integer64 + - +- Geometry Intersection trait + - +- Rust 2018 + - +- support for date and time fields + - +- Prebuild bindings + - +- Support for ndarray + - ## 0.5.0 -* [Bump geo-types from 0.3 -> 0.4](https://github.com/georust/gdal/pull/71) -* [Allow reading block-size of Rasters](https://github.com/georust/gdal/pull/67) -* [Add prebuilt-bindings GDAL 2.3 and GDAL 2.4](https://github.com/georust/gdal/pull/69) -* [Make GdalType trait public](https://github.com/georust/gdal/pull/66) -* [RasterBand to Ndarray, with failure](https://github.com/georust/gdal/pull/68) +- [Bump geo-types from 0.3 -> 0.4](https://github.com/georust/gdal/pull/71) +- [Allow reading block-size of Rasters](https://github.com/georust/gdal/pull/67) +- [Add prebuilt-bindings GDAL 2.3 and GDAL 2.4](https://github.com/georust/gdal/pull/69) +- [Make GdalType trait public](https://github.com/georust/gdal/pull/66) +- [RasterBand to Ndarray, with failure](https://github.com/georust/gdal/pull/68) ## 0.4.0 -* [Migrate to the `geo-types` crate](https://github.com/georust/gdal/pull/60) -* [Replace `error-chain` with `failure`](https://github.com/georust/gdal/pull/58) -* [Use `bindgen` to generate the low-level bindings](https://github.com/georust/gdal/pull/55) + +- [Migrate to the `geo-types` crate](https://github.com/georust/gdal/pull/60) +- [Replace `error-chain` with `failure`](https://github.com/georust/gdal/pull/58) +- [Use `bindgen` to generate the low-level bindings](https://github.com/georust/gdal/pull/55) ## 0.3.0 -* [Add support for creating a SpatialRef from a esri "wkt" definition](https://github.com/georust/gdal/pull/37) -* [Travis now uses GDAL 2.x](https://github.com/georust/gdal/pull/36) -* [API extensions](https://github.com/georust/gdal/pull/35) -* [Extend the existing possibilities of writing ogr datasets](https://github.com/georust/gdal/pull/31) -* [Allow to transform ogr geometries to other SRS](https://github.com/georust/gdal/pull/29) -* [Move ffi into a seperate crate](https://github.com/georust/gdal/pull/26) -* [Added rasterband.rs and moved all band functions](https://github.com/georust/gdal/pull/24) +- [Add support for creating a SpatialRef from a esri "wkt" definition](https://github.com/georust/gdal/pull/37) +- [Travis now uses GDAL 2.x](https://github.com/georust/gdal/pull/36) +- [API extensions](https://github.com/georust/gdal/pull/35) +- [Extend the existing possibilities of writing ogr datasets](https://github.com/georust/gdal/pull/31) +- [Allow to transform ogr geometries to other SRS](https://github.com/georust/gdal/pull/29) +- [Move ffi into a seperate crate](https://github.com/georust/gdal/pull/26) +- [Added rasterband.rs and moved all band functions](https://github.com/georust/gdal/pull/24) ## 0.2.1 -* [First version of metadata handling](https://github.com/georust/gdal/pull/21) +- [First version of metadata handling](https://github.com/georust/gdal/pull/21) diff --git a/Cargo.toml b/Cargo.toml index 48872c21..8c6878b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ thiserror = "1.0" libc = "0.2" geo-types = { version = "0.7.0" } gdal-sys = { path = "gdal-sys", version = "^0.3"} -ndarray = {version = "0.14", optional = true } +ndarray = {version = "0.15", optional = true } chrono = { version = "0.4", optional = true } bitflags = "1.2" diff --git a/gdal-sys/Cargo.toml b/gdal-sys/Cargo.toml index 3134e533..f16e6dfb 100644 --- a/gdal-sys/Cargo.toml +++ b/gdal-sys/Cargo.toml @@ -11,6 +11,6 @@ edition = "2018" libc = "0.2" [build-dependencies] -bindgen = { version = "0.57", optional = true } +bindgen = { version = "0.58", optional = true } pkg-config = "0.3" semver = "0.11" diff --git a/gdal-sys/build.rs b/gdal-sys/build.rs index e75c71c6..21d82f62 100644 --- a/gdal-sys/build.rs +++ b/gdal-sys/build.rs @@ -13,12 +13,12 @@ pub fn write_bindings(include_paths: Vec, out_path: &Path) { .header("wrapper.h") .constified_enum_module(".*") .ctypes_prefix("libc") - .whitelist_function("CPL.*") - .whitelist_function("GDAL.*") - .whitelist_function("OGR.*") - .whitelist_function("OSR.*") - .whitelist_function("OCT.*") - .whitelist_function("VSI.*"); + .allowlist_function("CPL.*") + .allowlist_function("GDAL.*") + .allowlist_function("OGR.*") + .allowlist_function("OSR.*") + .allowlist_function("OCT.*") + .allowlist_function("VSI.*"); for path in include_paths { builder = builder.clang_arg("-I"); diff --git a/gdal-sys/src/lib.rs b/gdal-sys/src/lib.rs index a38a13a8..8b199c5a 100644 --- a/gdal-sys/src/lib.rs +++ b/gdal-sys/src/lib.rs @@ -1,5 +1,6 @@ #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] +#![allow(clippy::upper_case_acronyms)] include!(concat!(env!("OUT_DIR"), "/bindings.rs")); diff --git a/src/spatial_ref/tests.rs b/src/spatial_ref/tests.rs index 06354017..e97276fc 100644 --- a/src/spatial_ref/tests.rs +++ b/src/spatial_ref/tests.rs @@ -58,10 +58,10 @@ fn comparison() { let spatial_ref4 = SpatialRef::from_proj4("+proj=longlat +datum=WGS84 +no_defs ").unwrap(); let spatial_ref5 = SpatialRef::from_esri("GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]]").unwrap(); - assert_eq!(true, spatial_ref1 == spatial_ref2); - assert_eq!(false, spatial_ref2 == spatial_ref3); - assert_eq!(true, spatial_ref4 == spatial_ref2); - assert_eq!(true, spatial_ref5 == spatial_ref4); + assert!(spatial_ref1 == spatial_ref2); + assert!(spatial_ref2 != spatial_ref3); + assert!(spatial_ref4 == spatial_ref2); + assert!(spatial_ref5 == spatial_ref4); } #[test] @@ -155,7 +155,7 @@ fn failing_transformation() { let trafo = CoordTransform::new(&wgs84, &dhd_2).unwrap(); let r = trafo.transform_coords(&mut x, &mut y, &mut z); - assert_eq!(r.is_err(), true); + assert!(r.is_err()); let wgs84 = SpatialRef::from_epsg(4326).unwrap(); let webmercator = SpatialRef::from_epsg(3857).unwrap(); @@ -174,7 +174,7 @@ fn failing_transformation() { let trafo = CoordTransform::new(&wgs84, &webmercator).unwrap(); let r = trafo.transform_coords(&mut x, &mut y, &mut z); - assert_eq!(r.is_err(), true); + assert!(r.is_err()); if let GdalError::InvalidCoordinateRange { .. } = r.unwrap_err() { // assert_eq!(msg, &Some("latitude or longitude exceeded limits".into())); } else { diff --git a/src/vector/feature.rs b/src/vector/feature.rs index d29209e3..36254838 100644 --- a/src/vector/feature.rs +++ b/src/vector/feature.rs @@ -385,7 +385,7 @@ impl<'a> Feature<'a> { if rv != OGRErr::OGRERR_NONE { return Err(GdalError::OgrError { err: rv, - method_name: "OGR_G_SetGeometry", + method_name: "OGR_F_SetGeometry", }); } self.geometry[0] = geom; diff --git a/src/vector/geometry.rs b/src/vector/geometry.rs index 8b3766cc..72d5bd94 100644 --- a/src/vector/geometry.rs +++ b/src/vector/geometry.rs @@ -1,7 +1,7 @@ use crate::spatial_ref::{CoordTransform, SpatialRef}; use crate::utils::{_last_null_pointer_err, _string}; use gdal_sys::{self, OGRErr, OGRGeometryH, OGRwkbGeometryType}; -use libc::{c_double, c_int, c_void}; +use libc::{c_char, c_double, c_int, c_void}; use std::cell::RefCell; use std::ffi::CString; use std::fmt::{self, Debug}; @@ -48,7 +48,7 @@ impl Geometry { /// This method operates on a raw C pointer pub unsafe fn set_c_geometry(&self, c_geometry: OGRGeometryH) { assert!(!self.has_gdal_ptr()); - assert_eq!(self.owned, false); + assert!(!self.owned); *(self.c_geometry_ref.borrow_mut()) = Some(c_geometry); } @@ -75,7 +75,9 @@ impl Geometry { /// [WKT](https://en.wikipedia.org/wiki/Well-known_text) string. pub fn from_wkt(wkt: &str) -> Result { let c_wkt = CString::new(wkt)?; - let mut c_wkt_ptr = c_wkt.into_raw(); + // OGR_G_CreateFromWkt does not write to the pointed-to memory, but this is not reflected + // in its signature (`char**` instead of `char const**`), so we need a scary looking cast. + let mut c_wkt_ptr = c_wkt.as_ptr() as *mut c_char; let mut c_geom = null_mut(); let rv = unsafe { gdal_sys::OGR_G_CreateFromWkt(&mut c_wkt_ptr, null_mut(), &mut c_geom) }; if rv != OGRErr::OGRERR_NONE { diff --git a/src/vector/layer.rs b/src/vector/layer.rs index df69a997..70649159 100644 --- a/src/vector/layer.rs +++ b/src/vector/layer.rs @@ -14,6 +14,7 @@ use std::{convert::TryInto, ffi::CString, marker::PhantomData}; use crate::errors::*; /// Layer capabilities +#[allow(clippy::upper_case_acronyms)] pub enum LayerCaps { /// Layer capability for random read OLCRandomRead, diff --git a/src/vector/sql.rs b/src/vector/sql.rs index 67fcc602..decd23d5 100644 --- a/src/vector/sql.rs +++ b/src/vector/sql.rs @@ -29,6 +29,7 @@ impl<'a> Drop for ResultSet<'a> { /// Represents valid SQL dialects to use in SQL queries. See /// +#[allow(clippy::upper_case_acronyms)] pub enum Dialect { /// Use the default dialect. This is OGR SQL unless the underlying driver has a native dialect, /// such as MySQL, Postgres, Oracle, etc. diff --git a/src/vector/vector_tests/mod.rs b/src/vector/vector_tests/mod.rs index 1fff5f1b..b6845135 100644 --- a/src/vector/vector_tests/mod.rs +++ b/src/vector/vector_tests/mod.rs @@ -70,11 +70,11 @@ fn test_layer_capabilities() { let mut ds = Dataset::open(fixture!("roads.geojson")).unwrap(); let layer = ds.layer(0).unwrap(); - assert_eq!(layer.has_capability(OLCFastSpatialFilter), false); - assert_eq!(layer.has_capability(OLCFastFeatureCount), true); - assert_eq!(layer.has_capability(OLCFastGetExtent), false); - assert_eq!(layer.has_capability(OLCRandomRead), true); - assert_eq!(layer.has_capability(OLCStringsAsUTF8), true); + assert!(!layer.has_capability(OLCFastSpatialFilter)); + assert!(layer.has_capability(OLCFastFeatureCount)); + assert!(!layer.has_capability(OLCFastGetExtent)); + assert!(layer.has_capability(OLCRandomRead)); + assert!(layer.has_capability(OLCStringsAsUTF8)); } fn ds_with_layer(ds_name: &str, layer_name: &str, f: F)