@@ -385,32 +385,44 @@ impl SpatialRef {
385385 unsafe { gdal_sys:: OSRIsVertical ( self . 0 ) == 1 }
386386 }
387387
388- pub fn get_axis_orientation ( & self , target_key : & str , axis : i32 ) -> AxisOrientationType {
389- // We can almost safely assume that if we fail to build a CString then the input
390- // is not a valide key.
388+ pub fn get_axis_orientation ( & self , target_key : & str , axis : i32 ) -> Result < AxisOrientationType > {
391389 let mut orientation = gdal_sys:: OGRAxisOrientation :: OAO_Other ;
392- if let Ok ( c_str) = CString :: new ( target_key) {
393- unsafe {
394- gdal_sys:: OSRGetAxis ( self . 0 , c_str. as_ptr ( ) , axis as c_int , & mut orientation)
395- } ;
390+ let c_ptr = unsafe {
391+ gdal_sys:: OSRGetAxis (
392+ self . 0 ,
393+ CString :: new ( target_key) ?. as_ptr ( ) ,
394+ axis as c_int ,
395+ & mut orientation,
396+ )
397+ } ;
398+ // null ptr indicate a failure (but no CPLError) see Gdal documentation.
399+ if c_ptr. is_null ( ) {
400+ Err ( GdalError :: AxisNotFoundError {
401+ key : target_key. into ( ) ,
402+ method_name : "OSRGetAxis" ,
403+ } )
404+ } else {
405+ Ok ( orientation)
396406 }
397- orientation
398407 }
399408
400- pub fn get_axis_name ( & self , target_key : & str , axis : i32 ) -> Option < String > {
409+ pub fn get_axis_name ( & self , target_key : & str , axis : i32 ) -> Result < String > {
401410 // See get_axis_orientation
402- if let Ok ( c_str) = CString :: new ( target_key) {
403- let c_ptr = unsafe {
404- gdal_sys:: OSRGetAxis ( self . 0 , c_str. as_ptr ( ) , axis as c_int , ptr:: null_mut ( ) )
405- } ;
406- // null ptr indicate a failure (but no CPLError) see Gdal documentation.
407- if c_ptr. is_null ( ) {
408- None
409- } else {
410- Some ( _string ( c_ptr) )
411- }
411+ let c_ptr = unsafe {
412+ gdal_sys:: OSRGetAxis (
413+ self . 0 ,
414+ CString :: new ( target_key) ?. as_ptr ( ) ,
415+ axis as c_int ,
416+ ptr:: null_mut ( ) ,
417+ )
418+ } ;
419+ if c_ptr. is_null ( ) {
420+ Err ( GdalError :: AxisNotFoundError {
421+ key : target_key. into ( ) ,
422+ method_name : "OSRGetAxis" ,
423+ } )
412424 } else {
413- None
425+ Ok ( _string ( c_ptr ) )
414426 }
415427 }
416428
0 commit comments