diff --git a/CHANGES.md b/CHANGES.md index e24c393b..cc0d52f0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,7 +9,7 @@ let dataset = Dataset::open_ex( "roads.geojson", - DatasetOptions { + DatasetOptions { open_flags: GdalOpenFlags::GDAL_OF_UPDATE|GdalOpenFlags::GDAL_OF_VECTOR, ..DatasetOptions::default() } @@ -31,7 +31,7 @@ ``` * 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 @@ -64,6 +64,8 @@ ``` * * 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 diff --git a/build.rs b/build.rs index 9b3f04c6..93da50e5 100644 --- a/build.rs +++ b/build.rs @@ -26,10 +26,10 @@ fn main() { let detected_version = Version::parse(semver_substring).expect("Could not parse gdal version!"); if detected_version.major < 2 { - panic!(format!( + panic!( "The GDAL crate requires a GDAL version >= 2.0.0. Found {}", detected_version.to_string() - )); + ); } println!("cargo:rustc-cfg=gdal_{}", detected_version.major); diff --git a/examples/read_write_ogr_datetime.rs b/examples/read_write_ogr_datetime.rs index c6bbd486..9bcb212f 100644 --- a/examples/read_write_ogr_datetime.rs +++ b/examples/read_write_ogr_datetime.rs @@ -1,7 +1,5 @@ -use gdal::errors::Result; - #[cfg(feature = "datetime")] -fn run() -> Result<()> { +fn run() -> gdal::errors::Result<()> { use chrono::Duration; use gdal::vector::{Defn, Feature, FieldDefn, FieldValue}; use gdal::{Dataset, Driver}; @@ -60,11 +58,13 @@ fn run() -> Result<()> { } #[cfg(not(feature = "datetime"))] -fn run() -> Result<()> { +fn run() { println!("gdal crate was build without datetime support"); - Ok(()) } fn main() { + #[cfg(feature = "datetime")] run().unwrap(); + #[cfg(not(feature = "datetime"))] + run(); } diff --git a/src/dataset.rs b/src/dataset.rs index 08afc3d6..7934c2f5 100644 --- a/src/dataset.rs +++ b/src/dataset.rs @@ -146,7 +146,9 @@ impl Dataset { } /// Open a dataset with extended options. See - /// [GDALOpenEx]. + /// [`GDALOpenEx`]. + /// + /// [`GDALOpenEx`]: https://gdal.org/doxygen/gdal_8h.html#a9cb8585d0b3c16726b08e25bcc94274a pub fn open_ex(path: &Path, options: DatasetOptions) -> Result { _register_drivers(); let filename = path.to_string_lossy(); @@ -315,6 +317,39 @@ impl Dataset { } } + /// Builds overviews for the current `Dataset`. See [`GDALBuildOverviews`]. + /// + /// # Arguments + /// * `resampling` - resampling method, as accepted by GDAL, e.g. `"CUBIC"` + /// * `overviews` - list of overview decimation factors, e.g. `&[2, 4, 8, 16, 32]` + /// * `bands` - list of bands to build the overviews for, or empty for all bands + /// + /// [`GDALBuildOverviews`]: https://gdal.org/doxygen/gdal_8h.html#a767f4456a6249594ee18ea53f68b7e80 + pub fn build_overviews( + &mut self, + resampling: &str, + overviews: &[i32], + bands: &[i32], + ) -> Result<()> { + let c_resampling = CString::new(resampling)?; + let rv = unsafe { + gdal_sys::GDALBuildOverviews( + self.c_dataset, + c_resampling.as_ptr(), + overviews.len() as i32, + overviews.as_ptr() as *mut i32, + bands.len() as i32, + bands.as_ptr() as *mut i32, + None, + null_mut(), + ) + }; + if rv != CPLErr::CE_None { + return Err(_last_cpl_err(rv)); + } + Ok(()) + } + fn child_layer(&self, c_layer: OGRLayerH) -> Layer { unsafe { Layer::from_c_layer(self, c_layer) } }