Skip to content

Commit

Permalink
Merge pull request #164 from lnicola/dataset-build-overviews
Browse files Browse the repository at this point in the history
Add Dataset::build_overviews
  • Loading branch information
jdroenner authored Feb 23, 2021
2 parents 29a9585 + 3765736 commit 8af8dfb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
6 changes: 4 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -31,7 +31,7 @@
```

* Add more functions to SpatialRef implementation
* <https://github.com/georust/gdal/pull/145>
* <https://github.com/georust/gdal/pull/145>
* **Breaking**: Change `Feature::field` return type from
`Result<FieldValue>` to `Result<Option<FieldValue>>`. Fields
can be null. Before this change, if a field was null, the value
Expand Down Expand Up @@ -64,6 +64,8 @@
```
* <https://github.com/georust/gdal/pull/134>
* Add basic support to read overviews
* Added a `Dataset::build_overviews` method
* <https://github.com/georust/gdal/pull/164>
* BREAKING: update geo-types to 0.7.0. geo-types Coordinate<T> now implement `Debug`
* <https://github.com/georust/gdal/pull/146>
* Deprecated `SpatialRef::get_axis_mapping_strategy` - migrate to
Expand Down
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions examples/read_write_ogr_datetime.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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();
}
37 changes: 36 additions & 1 deletion src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Dataset> {
_register_drivers();
let filename = path.to_string_lossy();
Expand Down Expand Up @@ -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) }
}
Expand Down

0 comments on commit 8af8dfb

Please sign in to comment.