Skip to content

Commit ed97cfe

Browse files
authored
Merge pull request #152 from michaelkirk/mkirk/conventional-getters
conventional rust naming
2 parents b43596c + ef5140f commit ed97cfe

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
* Add basic support to read overviews
3838
* BREAKING: update geo-types to 0.7.0. geo-types Coordinate<T> now implement `Debug`
3939
* <https://github.com/georust/gdal/pull/146>
40+
* Deprecated `SpatialRef::get_axis_mapping_strategy` - migrate to
41+
`SpatialRef::axis_mapping_strategy` instead.
4042

4143
## 0.7.1
4244
* fix docs.rs build for gdal-sys

src/spatial_ref/srs.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,15 @@ impl SpatialRef {
315315
}
316316

317317
#[cfg(major_ge_3)]
318-
pub fn get_name(&self) -> Result<String> {
318+
pub fn name(&self) -> Result<String> {
319319
let c_ptr = unsafe { gdal_sys::OSRGetName(self.0) };
320320
if c_ptr.is_null() {
321321
return Err(_last_null_pointer_err("OSRGetName"));
322322
}
323323
Ok(_string(c_ptr))
324324
}
325325

326-
pub fn get_angular_units_name(&self) -> Result<String> {
326+
pub fn angular_units_name(&self) -> Result<String> {
327327
let mut c_ptr = ptr::null_mut();
328328
unsafe { gdal_sys::OSRGetAngularUnits(self.0, &mut c_ptr) };
329329
if c_ptr.is_null() {
@@ -332,11 +332,11 @@ impl SpatialRef {
332332
Ok(_string(c_ptr))
333333
}
334334

335-
pub fn get_angular_units(&self) -> f64 {
335+
pub fn angular_units(&self) -> f64 {
336336
unsafe { gdal_sys::OSRGetAngularUnits(self.0, ptr::null_mut()) }
337337
}
338338

339-
pub fn get_linear_units_name(&self) -> Result<String> {
339+
pub fn linear_units_name(&self) -> Result<String> {
340340
let mut c_ptr = ptr::null_mut();
341341
unsafe { gdal_sys::OSRGetLinearUnits(self.0, &mut c_ptr) };
342342
if c_ptr.is_null() {
@@ -345,7 +345,7 @@ impl SpatialRef {
345345
Ok(_string(c_ptr))
346346
}
347347

348-
pub fn get_linear_units(&self) -> f64 {
348+
pub fn linear_units(&self) -> f64 {
349349
unsafe { gdal_sys::OSRGetLinearUnits(self.0, ptr::null_mut()) }
350350
}
351351

@@ -385,7 +385,7 @@ impl SpatialRef {
385385
unsafe { gdal_sys::OSRIsVertical(self.0) == 1 }
386386
}
387387

388-
pub fn get_axis_orientation(&self, target_key: &str, axis: i32) -> Result<AxisOrientationType> {
388+
pub fn axis_orientation(&self, target_key: &str, axis: i32) -> Result<AxisOrientationType> {
389389
let mut orientation = gdal_sys::OGRAxisOrientation::OAO_Other;
390390
let c_ptr = unsafe {
391391
gdal_sys::OSRGetAxis(
@@ -406,7 +406,7 @@ impl SpatialRef {
406406
}
407407
}
408408

409-
pub fn get_axis_name(&self, target_key: &str, axis: i32) -> Result<String> {
409+
pub fn axis_name(&self, target_key: &str, axis: i32) -> Result<String> {
410410
// See get_axis_orientation
411411
let c_ptr = unsafe {
412412
gdal_sys::OSRGetAxis(
@@ -427,7 +427,7 @@ impl SpatialRef {
427427
}
428428

429429
#[cfg(all(major_ge_3, minor_ge_1))]
430-
pub fn get_axes_count(&self) -> i32 {
430+
pub fn axes_count(&self) -> i32 {
431431
unsafe { gdal_sys::OSRGetAxesCount(self.0) }
432432
}
433433

@@ -439,12 +439,18 @@ impl SpatialRef {
439439
}
440440

441441
#[cfg(major_ge_3)]
442+
#[deprecated(note = "use `axis_mapping_strategy` instead")]
442443
pub fn get_axis_mapping_strategy(&self) -> gdal_sys::OSRAxisMappingStrategy::Type {
444+
self.axis_mapping_strategy()
445+
}
446+
447+
#[cfg(major_ge_3)]
448+
pub fn axis_mapping_strategy(&self) -> gdal_sys::OSRAxisMappingStrategy::Type {
443449
unsafe { gdal_sys::OSRGetAxisMappingStrategy(self.0) }
444450
}
445451

446452
#[cfg(major_ge_3)]
447-
pub fn get_area_of_use(&self) -> Option<AreaOfUse> {
453+
pub fn area_of_use(&self) -> Option<AreaOfUse> {
448454
let mut c_area_name: *const libc::c_char = ptr::null_mut();
449455
let (mut w_long, mut s_lat, mut e_long, mut n_lat): (f64, f64, f64, f64) =
450456
(0.0, 0.0, 0.0, 0.0);

src/spatial_ref/tests.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,22 +212,22 @@ fn auto_identify() {
212212
fn axis_mapping_strategy() {
213213
let spatial_ref = SpatialRef::from_epsg(4326).unwrap();
214214
assert_eq!(
215-
spatial_ref.get_axis_mapping_strategy(),
215+
spatial_ref.axis_mapping_strategy(),
216216
gdal_sys::OSRAxisMappingStrategy::OAMS_AUTHORITY_COMPLIANT
217217
);
218218
spatial_ref
219219
.set_axis_mapping_strategy(gdal_sys::OSRAxisMappingStrategy::OAMS_TRADITIONAL_GIS_ORDER);
220220
assert_eq!(
221-
spatial_ref.get_axis_mapping_strategy(),
221+
spatial_ref.axis_mapping_strategy(),
222222
gdal_sys::OSRAxisMappingStrategy::OAMS_TRADITIONAL_GIS_ORDER
223223
);
224224
}
225225

226226
#[cfg(major_ge_3)]
227227
#[test]
228-
fn get_area_of_use() {
228+
fn area_of_use() {
229229
let spatial_ref = SpatialRef::from_epsg(4326).unwrap();
230-
let area_of_use = spatial_ref.get_area_of_use().unwrap();
230+
let area_of_use = spatial_ref.area_of_use().unwrap();
231231
assert_almost_eq(area_of_use.west_lon_degree, -180.0);
232232
assert_almost_eq(area_of_use.south_lat_degree, -90.0);
233233
assert_almost_eq(area_of_use.east_lon_degree, 180.0);
@@ -238,26 +238,26 @@ fn get_area_of_use() {
238238
#[test]
239239
fn get_name() {
240240
let spatial_ref = SpatialRef::from_epsg(4326).unwrap();
241-
let name = spatial_ref.get_name().unwrap();
241+
let name = spatial_ref.name().unwrap();
242242
assert_eq!(name, "WGS 84");
243243
}
244244

245245
#[test]
246246
fn get_units_epsg4326() {
247247
let spatial_ref = SpatialRef::from_epsg(4326).unwrap();
248248

249-
let angular_units_name = spatial_ref.get_angular_units_name().unwrap();
249+
let angular_units_name = spatial_ref.angular_units_name().unwrap();
250250
assert_eq!(angular_units_name.to_lowercase(), "degree");
251-
let to_radians = spatial_ref.get_angular_units();
251+
let to_radians = spatial_ref.angular_units();
252252
assert_almost_eq(to_radians, 0.01745329);
253253
}
254254

255255
#[test]
256256
fn get_units_epsg2154() {
257257
let spatial_ref = SpatialRef::from_epsg(2154).unwrap();
258-
let linear_units_name = spatial_ref.get_linear_units_name().unwrap();
258+
let linear_units_name = spatial_ref.linear_units_name().unwrap();
259259
assert_eq!(linear_units_name.to_lowercase(), "metre");
260-
let to_meters = spatial_ref.get_linear_units();
260+
let to_meters = spatial_ref.linear_units();
261261
assert_almost_eq(to_meters, 1.0);
262262
}
263263

@@ -295,11 +295,11 @@ fn crs_axis() {
295295
let spatial_ref = SpatialRef::from_epsg(4326).unwrap();
296296

297297
#[cfg(all(major_ge_3, minor_ge_1))]
298-
assert_eq!(spatial_ref.get_axes_count(), 2);
298+
assert_eq!(spatial_ref.axes_count(), 2);
299299

300-
let orientation = spatial_ref.get_axis_orientation("GEOGCS", 0).unwrap();
300+
let orientation = spatial_ref.axis_orientation("GEOGCS", 0).unwrap();
301301
assert_eq!(orientation, gdal_sys::OGRAxisOrientation::OAO_North);
302-
assert!(spatial_ref.get_axis_name("GEOGCS", 0).is_ok());
303-
assert!(spatial_ref.get_axis_name("DO_NO_EXISTS", 0).is_err());
304-
assert!(spatial_ref.get_axis_orientation("DO_NO_EXISTS", 0).is_err());
302+
assert!(spatial_ref.axis_name("GEOGCS", 0).is_ok());
303+
assert!(spatial_ref.axis_name("DO_NO_EXISTS", 0).is_err());
304+
assert!(spatial_ref.axis_orientation("DO_NO_EXISTS", 0).is_err());
305305
}

0 commit comments

Comments
 (0)