Skip to content

Commit

Permalink
Add Dataset::build_overviews
Browse files Browse the repository at this point in the history
  • Loading branch information
lnicola committed Feb 17, 2021
1 parent 29a9585 commit 5623d4d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 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
31 changes: 31 additions & 0 deletions src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,37 @@ impl Dataset {
}
}

/// Builds overviews for the current `Dataset`.
///
/// # 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
pub fn build_overviews(
&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 {
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 5623d4d

Please sign in to comment.