From 1974267d96828c9e5320af98b507926516086350 Mon Sep 17 00:00:00 2001 From: "Simeon H.K. Fitch" Date: Sun, 1 Oct 2023 12:41:49 -0400 Subject: [PATCH] GDAL version regressions. --- src/spatial_ref/transform.rs | 26 ++++++++++++++++++++++---- src/vector/ops/transformations.rs | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/spatial_ref/transform.rs b/src/spatial_ref/transform.rs index 7e2e11d02..b672445fc 100644 --- a/src/spatial_ref/transform.rs +++ b/src/spatial_ref/transform.rs @@ -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; @@ -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()) @@ -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, + }); } } diff --git a/src/vector/ops/transformations.rs b/src/vector/ops/transformations.rs index 9ad19545e..af407c210 100644 --- a/src/vector/ops/transformations.rs +++ b/src/vector/ops/transformations.rs @@ -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() {