@@ -78,6 +78,17 @@ impl CoordTransform {
7878 }
7979}
8080
81+ #[ derive( Debug , Clone ) ]
82+ pub struct AreaOfUse {
83+ pub west_lon_degree : f64 ,
84+ pub south_lat_degree : f64 ,
85+ pub east_lon_degree : f64 ,
86+ pub north_lat_degree : f64 ,
87+ pub name : String ,
88+ }
89+
90+ pub type AxisOrientationType = gdal_sys:: OGRAxisOrientation :: Type ;
91+
8192#[ derive( Debug ) ]
8293pub struct SpatialRef ( OGRSpatialReferenceH ) ;
8394
@@ -303,6 +314,123 @@ impl SpatialRef {
303314 }
304315 }
305316
317+ #[ cfg( major_ge_3) ]
318+ pub fn get_name ( & self ) -> Result < String > {
319+ let c_ptr = unsafe { gdal_sys:: OSRGetName ( self . 0 ) } ;
320+ if c_ptr. is_null ( ) {
321+ return Err ( _last_null_pointer_err ( "OSRGetName" ) ) ;
322+ }
323+ Ok ( _string ( c_ptr) )
324+ }
325+
326+ pub fn get_angular_units_name ( & self ) -> Result < String > {
327+ let mut c_ptr = ptr:: null_mut ( ) ;
328+ unsafe { gdal_sys:: OSRGetAngularUnits ( self . 0 , & mut c_ptr) } ;
329+ if c_ptr. is_null ( ) {
330+ return Err ( _last_null_pointer_err ( "OSRGetAngularUnits" ) ) ;
331+ }
332+ Ok ( _string ( c_ptr) )
333+ }
334+
335+ pub fn get_angular_units ( & self ) -> f64 {
336+ unsafe { gdal_sys:: OSRGetAngularUnits ( self . 0 , ptr:: null_mut ( ) ) }
337+ }
338+
339+ pub fn get_linear_units_name ( & self ) -> Result < String > {
340+ let mut c_ptr = ptr:: null_mut ( ) ;
341+ unsafe { gdal_sys:: OSRGetLinearUnits ( self . 0 , & mut c_ptr) } ;
342+ if c_ptr. is_null ( ) {
343+ return Err ( _last_null_pointer_err ( "OSRGetLinearUnits" ) ) ;
344+ }
345+ Ok ( _string ( c_ptr) )
346+ }
347+
348+ pub fn get_linear_units ( & self ) -> f64 {
349+ unsafe { gdal_sys:: OSRGetLinearUnits ( self . 0 , ptr:: null_mut ( ) ) }
350+ }
351+
352+ #[ inline]
353+ pub fn is_geographic ( & self ) -> bool {
354+ unsafe { gdal_sys:: OSRIsGeographic ( self . 0 ) == 1 }
355+ }
356+
357+ #[ inline]
358+ #[ cfg( all( major_ge_3, minor_ge_1) ) ]
359+ pub fn is_derived_geographic ( & self ) -> bool {
360+ unsafe { gdal_sys:: OSRIsDerivedGeographic ( self . 0 ) == 1 }
361+ }
362+
363+ #[ inline]
364+ pub fn is_local ( & self ) -> bool {
365+ unsafe { gdal_sys:: OSRIsLocal ( self . 0 ) == 1 }
366+ }
367+
368+ #[ inline]
369+ pub fn is_projected ( & self ) -> bool {
370+ unsafe { gdal_sys:: OSRIsProjected ( self . 0 ) == 1 }
371+ }
372+
373+ #[ inline]
374+ pub fn is_compound ( & self ) -> bool {
375+ unsafe { gdal_sys:: OSRIsCompound ( self . 0 ) == 1 }
376+ }
377+
378+ #[ inline]
379+ pub fn is_geocentric ( & self ) -> bool {
380+ unsafe { gdal_sys:: OSRIsGeocentric ( self . 0 ) == 1 }
381+ }
382+
383+ #[ inline]
384+ pub fn is_vertical ( & self ) -> bool {
385+ unsafe { gdal_sys:: OSRIsVertical ( self . 0 ) == 1 }
386+ }
387+
388+ pub fn get_axis_orientation ( & self , target_key : & str , axis : i32 ) -> Result < AxisOrientationType > {
389+ let mut orientation = gdal_sys:: OGRAxisOrientation :: OAO_Other ;
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)
406+ }
407+ }
408+
409+ pub fn get_axis_name ( & self , target_key : & str , axis : i32 ) -> Result < String > {
410+ // See get_axis_orientation
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+ } )
424+ } else {
425+ Ok ( _string ( c_ptr) )
426+ }
427+ }
428+
429+ #[ cfg( all( major_ge_3, minor_ge_1) ) ]
430+ pub fn get_axes_count ( & self ) -> i32 {
431+ unsafe { gdal_sys:: OSRGetAxesCount ( self . 0 ) }
432+ }
433+
306434 #[ cfg( major_ge_3) ]
307435 pub fn set_axis_mapping_strategy ( & self , strategy : gdal_sys:: OSRAxisMappingStrategy :: Type ) {
308436 unsafe {
@@ -315,6 +443,35 @@ impl SpatialRef {
315443 unsafe { gdal_sys:: OSRGetAxisMappingStrategy ( self . 0 ) }
316444 }
317445
446+ #[ cfg( major_ge_3) ]
447+ pub fn get_area_of_use ( & self ) -> Option < AreaOfUse > {
448+ let mut c_area_name: * const libc:: c_char = ptr:: null_mut ( ) ;
449+ let ( mut w_long, mut s_lat, mut e_long, mut n_lat) : ( f64 , f64 , f64 , f64 ) =
450+ ( 0.0 , 0.0 , 0.0 , 0.0 ) ;
451+ let ret_val = unsafe {
452+ gdal_sys:: OSRGetAreaOfUse (
453+ self . 0 ,
454+ & mut w_long,
455+ & mut s_lat,
456+ & mut e_long,
457+ & mut n_lat,
458+ & mut c_area_name,
459+ ) == 1
460+ } ;
461+
462+ if ret_val {
463+ Some ( AreaOfUse {
464+ west_lon_degree : w_long,
465+ south_lat_degree : s_lat,
466+ east_lon_degree : e_long,
467+ north_lat_degree : n_lat,
468+ name : _string ( c_area_name) ,
469+ } )
470+ } else {
471+ None
472+ }
473+ }
474+
318475 // TODO: should this take self instead of &self?
319476 pub fn to_c_hsrs ( & self ) -> OGRSpatialReferenceH {
320477 self . 0
0 commit comments