Skip to content

Commit

Permalink
Move RasterIOExtraArg to raster::types
Browse files Browse the repository at this point in the history
  • Loading branch information
julienr committed Feb 26, 2023
1 parent 520c17d commit 84fbaf3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 62 deletions.
62 changes: 1 addition & 61 deletions src/raster/rasterband.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::dataset::Dataset;
use crate::gdal_major_object::MajorObject;
use crate::metadata::Metadata;
use crate::raster::types::RasterIOExtraArg;
use crate::raster::{Buffer, GdalDataType, GdalType, ResampleAlg};
use crate::utils::{_last_cpl_err, _last_null_pointer_err, _string};
use gdal_sys::{
Expand Down Expand Up @@ -50,67 +51,6 @@ impl GdalMaskFlags {
}
}

/// Extra options used to read a raster.
///
/// For documentation, see `gdal_sys::GDALRasterIOExtraArg`.
#[derive(Debug)]
#[allow(clippy::upper_case_acronyms)]
pub struct RasterIOExtraArg {
pub n_version: usize,
pub e_resample_alg: ResampleAlg,
pub pfn_progress: gdal_sys::GDALProgressFunc,
p_progress_data: *mut libc::c_void,
pub b_floating_point_window_validity: usize,
pub df_x_off: f64,
pub df_y_off: f64,
pub df_x_size: f64,
pub df_y_size: f64,
}

impl Default for RasterIOExtraArg {
fn default() -> Self {
Self {
n_version: 1,
pfn_progress: None,
p_progress_data: std::ptr::null_mut(),
e_resample_alg: ResampleAlg::NearestNeighbour,
b_floating_point_window_validity: 0,
df_x_off: 0.0,
df_y_off: 0.0,
df_x_size: 0.0,
df_y_size: 0.0,
}
}
}

impl From<RasterIOExtraArg> for GDALRasterIOExtraArg {
fn from(arg: RasterIOExtraArg) -> Self {
let RasterIOExtraArg {
n_version,
e_resample_alg,
pfn_progress,
p_progress_data,
b_floating_point_window_validity,
df_x_off,
df_y_off,
df_x_size,
df_y_size,
} = arg;

GDALRasterIOExtraArg {
nVersion: n_version as c_int,
eResampleAlg: e_resample_alg.to_gdal(),
pfnProgress: pfn_progress,
pProgressData: p_progress_data,
bFloatingPointWindowValidity: b_floating_point_window_validity as c_int,
dfXOff: df_x_off,
dfYOff: df_y_off,
dfXSize: df_x_size,
dfYSize: df_y_size,
}
}
}

/// Represents a single band of a dataset.
///
/// This object carries the lifetime of the dataset that
Expand Down
64 changes: 63 additions & 1 deletion src/raster/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use gdal_sys::{
GDALAdjustValueToDataType, GDALDataType, GDALDataTypeIsConversionLossy, GDALDataTypeIsFloating,
GDALDataTypeIsInteger, GDALDataTypeIsSigned, GDALDataTypeUnion, GDALFindDataTypeForValue,
GDALGetDataTypeByName, GDALGetDataTypeName, GDALGetDataTypeSizeBits, GDALGetDataTypeSizeBytes,
GDALRIOResampleAlg,
GDALRIOResampleAlg, GDALRasterIOExtraArg,
};
use libc::c_int;
use std::ffi::CString;
use std::fmt::{Debug, Display, Formatter};

Expand Down Expand Up @@ -459,6 +460,67 @@ impl<T: GdalType> Buffer<T> {

pub type ByteBuffer = Buffer<u8>;

/// Extra options used to read a raster.
///
/// For documentation, see `gdal_sys::GDALRasterIOExtraArg`.
#[derive(Debug)]
#[allow(clippy::upper_case_acronyms)]
pub struct RasterIOExtraArg {
pub n_version: usize,
pub e_resample_alg: ResampleAlg,
pub pfn_progress: gdal_sys::GDALProgressFunc,
pub p_progress_data: *mut libc::c_void,
pub b_floating_point_window_validity: usize,
pub df_x_off: f64,
pub df_y_off: f64,
pub df_x_size: f64,
pub df_y_size: f64,
}

impl Default for RasterIOExtraArg {
fn default() -> Self {
Self {
n_version: 1,
pfn_progress: None,
p_progress_data: std::ptr::null_mut(),
e_resample_alg: ResampleAlg::NearestNeighbour,
b_floating_point_window_validity: 0,
df_x_off: 0.0,
df_y_off: 0.0,
df_x_size: 0.0,
df_y_size: 0.0,
}
}
}

impl From<RasterIOExtraArg> for GDALRasterIOExtraArg {
fn from(arg: RasterIOExtraArg) -> Self {
let RasterIOExtraArg {
n_version,
e_resample_alg,
pfn_progress,
p_progress_data,
b_floating_point_window_validity,
df_x_off,
df_y_off,
df_x_size,
df_y_size,
} = arg;

GDALRasterIOExtraArg {
nVersion: n_version as c_int,
eResampleAlg: e_resample_alg.to_gdal(),
pfnProgress: pfn_progress,
pProgressData: p_progress_data,
bFloatingPointWindowValidity: b_floating_point_window_validity as c_int,
dfXOff: df_x_off,
dfYOff: df_y_off,
dfXSize: df_x_size,
dfYSize: df_y_size,
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 84fbaf3

Please sign in to comment.