Skip to content

Commit

Permalink
GDAL version regressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
metasim committed Oct 1, 2023
1 parent d70211e commit 1974267
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions src/spatial_ref/transform.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::errors;
use crate::errors::GdalError;
use crate::spatial_ref::{CoordTransformOptions, SpatialRef, SpatialRefRef};
use crate::spatial_ref::{CoordTransformOptions, SpatialRef};
use crate::utils::{_last_cpl_err, _last_null_pointer_err};
use foreign_types::{foreign_type, ForeignType, ForeignTypeRef};
use foreign_types::{foreign_type, ForeignType};
use gdal_sys::{CPLErr, OGRCoordinateTransformationH};
use libc::c_int;
use std::ptr::null_mut;
Expand Down Expand Up @@ -52,20 +52,27 @@ impl CoordTransform {
Ok(unsafe { Self::from_ptr(c_obj) })
}

#[cfg(all(major_ge_3, minor_ge_4))]
/// Get the source coordinate system
pub fn source(&self) -> SpatialRef {
use crate::spatial_ref::SpatialRefRef;
use foreign_types::ForeignTypeRef;
let c_obj = unsafe { gdal_sys::OCTGetSourceCS(self.as_ptr()) };
let sr = unsafe { SpatialRefRef::from_ptr(c_obj) };
sr.to_owned()
}

#[cfg(all(major_ge_3, minor_ge_4))]
/// Get the target coordinate system
pub fn target(&self) -> SpatialRef {
use crate::spatial_ref::SpatialRefRef;
use foreign_types::ForeignTypeRef;
let c_obj = unsafe { gdal_sys::OCTGetTargetCS(self.as_ptr()) };
let sr = unsafe { SpatialRefRef::from_ptr(c_obj) };
sr.to_owned()
}

/// Convert `SpatialRef` to a string for error messages.
fn _sr_disp(srs: &SpatialRef) -> String {
srs.authority()
.or_else(|_| srs.to_proj4())
Expand Down Expand Up @@ -186,11 +193,22 @@ impl CoordTransform {
} else {
return Err(err);
};
Err(GdalError::InvalidCoordinateRange {
#[cfg(all(major_ge_3, minor_ge_4))]
return Err(GdalError::InvalidCoordinateRange {
from: Self::_sr_disp(&self.source()),
to: Self::_sr_disp(&self.target()),
msg,
})
});
#[cfg(not(all(major_ge_3, minor_ge_4)))]
// Prior to GDAL 3.5, we don't have a way to get
// the source and destinations `SpatialRef`'s provided
// to the constructor, and storing them for prior versions
// just for this one case requires code bloat
return Err(GdalError::InvalidCoordinateRange {
from: "source".into(),
to: "destination".into(),
msg,
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/vector/ops/transformations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl GeometryRef {
"Options to make_valid require GDAL >= 3.4".into(),
));
}
unsafe { gdal_sys::OGR_G_MakeValid(self.c_geometry()) }
unsafe { gdal_sys::OGR_G_MakeValid(self.as_ptr()) }
};

if c_geom.is_null() {
Expand Down

0 comments on commit 1974267

Please sign in to comment.