diff --git a/src/spatial_ref/mod.rs b/src/spatial_ref/mod.rs index 8facc725..b54cbff4 100644 --- a/src/spatial_ref/mod.rs +++ b/src/spatial_ref/mod.rs @@ -1,7 +1,7 @@ mod srs; -pub use srs::{ CoordTransform, SpatialRef, AxisOrientationType }; -pub use gdal_sys::{ OGRAxisOrientation }; +pub use gdal_sys::OGRAxisOrientation; +pub use srs::{AxisOrientationType, CoordTransform, SpatialRef}; #[cfg(test)] mod tests; diff --git a/src/spatial_ref/srs.rs b/src/spatial_ref/srs.rs index e9bed664..b2194323 100644 --- a/src/spatial_ref/srs.rs +++ b/src/spatial_ref/srs.rs @@ -89,7 +89,6 @@ pub struct AreaOfUse { pub type AxisOrientationType = gdal_sys::OGRAxisOrientation::Type; - #[derive(Debug)] pub struct SpatialRef(OGRSpatialReferenceH); @@ -349,7 +348,7 @@ impl SpatialRef { pub fn get_linear_units(&self) -> f64 { unsafe { gdal_sys::OSRGetLinearUnits(self.0, ptr::null_mut()) } } - + #[inline] pub fn is_geographic(&self) -> bool { unsafe { gdal_sys::OSRIsGeographic(self.0) == 1 } @@ -361,7 +360,7 @@ impl SpatialRef { unsafe { gdal_sys::OSRIsDerivedGeographic(self.0) == 1 } } - #[inline] + #[inline] pub fn is_local(&self) -> bool { unsafe { gdal_sys::OSRIsLocal(self.0) == 1 } } @@ -383,25 +382,33 @@ impl SpatialRef { #[inline] pub fn is_vertical(&self) -> bool { - unsafe { gdal_sys::OSRIsVertical(self.0) == 1 } + unsafe { gdal_sys::OSRIsVertical(self.0) == 1 } } - pub fn get_axis_orientation(&self, target_key: &str, axis: i32 ) -> AxisOrientationType { - // We can almost safely assume that if we fail to build a CString then the input - // is not a valide key. + pub fn get_axis_orientation(&self, target_key: &str, axis: i32) -> AxisOrientationType { + // We can almost safely assume that if we fail to build a CString then the input + // is not a valide key. let mut orientation = gdal_sys::OGRAxisOrientation::OAO_Other; - if let Ok(c_str) = CString::new(target_key) { - unsafe { gdal_sys::OSRGetAxis(self.0, c_str.as_ptr(), axis as c_int, &mut orientation) }; + if let Ok(c_str) = CString::new(target_key) { + unsafe { + gdal_sys::OSRGetAxis(self.0, c_str.as_ptr(), axis as c_int, &mut orientation) + }; } orientation } - pub fn get_axis_name(&self, target_key: &str, axis: i32 ) -> Option { + pub fn get_axis_name(&self, target_key: &str, axis: i32) -> Option { // See get_axis_orientation if let Ok(c_str) = CString::new(target_key) { - let c_ptr = unsafe { gdal_sys::OSRGetAxis(self.0, c_str.as_ptr(), axis as c_int, ptr::null_mut()) }; + let c_ptr = unsafe { + gdal_sys::OSRGetAxis(self.0, c_str.as_ptr(), axis as c_int, ptr::null_mut()) + }; // null ptr indicate a failure (but no CPLError) see Gdal documentation. - if c_ptr.is_null() { None } else { Some(_string(c_ptr)) } + if c_ptr.is_null() { + None + } else { + Some(_string(c_ptr)) + } } else { None } @@ -409,7 +416,7 @@ impl SpatialRef { #[cfg(all(major_ge_3, minor_ge_1))] pub fn get_axes_count(&self) -> i32 { - unsafe { gdal_sys::OSRGetAxesCount(self.0) } + unsafe { gdal_sys::OSRGetAxesCount(self.0) } } #[cfg(major_ge_3)] @@ -427,7 +434,8 @@ impl SpatialRef { #[cfg(major_ge_3)] pub fn get_area_of_use(&self) -> Option { let mut c_area_name: *const libc::c_char = ptr::null_mut(); - let (mut w_long, mut s_lat, mut e_long, mut n_lat): (f64, f64, f64, f64) = (0.0,0.0,0.0,0.0); + let (mut w_long, mut s_lat, mut e_long, mut n_lat): (f64, f64, f64, f64) = + (0.0, 0.0, 0.0, 0.0); let ret_val = unsafe { gdal_sys::OSRGetAreaOfUse( self.0, @@ -435,8 +443,8 @@ impl SpatialRef { &mut s_lat, &mut e_long, &mut n_lat, - &mut c_area_name - ) == 1 + &mut c_area_name, + ) == 1 }; if ret_val { @@ -445,7 +453,8 @@ impl SpatialRef { south_lat_degree: s_lat, east_lon_degree: e_long, north_lat_degree: n_lat, - name: _string(c_area_name) }) + name: _string(c_area_name), + }) } else { None } diff --git a/src/spatial_ref/tests.rs b/src/spatial_ref/tests.rs index 55ceffff..67ce0563 100644 --- a/src/spatial_ref/tests.rs +++ b/src/spatial_ref/tests.rs @@ -228,10 +228,10 @@ fn axis_mapping_strategy() { fn get_area_of_use() { let spatial_ref = SpatialRef::from_epsg(4326).unwrap(); let area_of_use = spatial_ref.get_area_of_use().unwrap(); - assert_eq!(area_of_use.west_lon_degree, -180.0); - assert_eq!(area_of_use.south_lat_degree, -90.0); - assert_eq!(area_of_use.east_lon_degree, 180.0); - assert_eq!(area_of_use.north_lat_degree, 90.0); + assert_almost_eq(area_of_use.west_lon_degree, -180.0); + assert_almost_eq(area_of_use.south_lat_degree, -90.0); + assert_almost_eq(area_of_use.east_lon_degree, 180.0); + assert_almost_eq(area_of_use.north_lat_degree, 90.0); } #[cfg(major_ge_3)] @@ -239,10 +239,9 @@ fn get_area_of_use() { fn get_name() { let spatial_ref = SpatialRef::from_epsg(4326).unwrap(); let name = spatial_ref.get_name().unwrap(); - assert_eq!(name,"WGS 84"); + assert_eq!(name, "WGS 84"); } - #[test] fn get_units_epsg4326() { let spatial_ref = SpatialRef::from_epsg(4326).unwrap(); @@ -287,24 +286,23 @@ fn predicats_epsg2154() { #[cfg(all(major_ge_3, minor_ge_1))] assert!(!spatial_ref_2154.is_derived_geographic()); -} +} //XXX Gdal 2 implementation is partial -#[cfg(major_ge_3)] +#[cfg(major_ge_3)] #[test] fn crs_axis() { let spatial_ref = SpatialRef::from_epsg(4326).unwrap(); #[cfg(all(major_ge_3, minor_ge_1))] - assert_eq!(spatial_ref.get_axes_count(),2); - - let orientation = spatial_ref.get_axis_orientation("GEOGCS",0); - assert_eq!(orientation,gdal_sys::OGRAxisOrientation::OAO_North); + assert_eq!(spatial_ref.get_axes_count(), 2); - assert!(spatial_ref.get_axis_name("GEOGCS",0).is_some()); - assert!(spatial_ref.get_axis_name("DO_NO_EXISTS",0).is_none()); + let orientation = spatial_ref.get_axis_orientation("GEOGCS", 0); + assert_eq!(orientation, gdal_sys::OGRAxisOrientation::OAO_North); - let orientation = spatial_ref.get_axis_orientation("DO_NO_EXISTS",0); + assert!(spatial_ref.get_axis_name("GEOGCS", 0).is_some()); + assert!(spatial_ref.get_axis_name("DO_NO_EXISTS", 0).is_none()); + + let orientation = spatial_ref.get_axis_orientation("DO_NO_EXISTS", 0); assert_eq!(orientation, gdal_sys::OGRAxisOrientation::OAO_Other); } -