Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more SpatialRef methods #145

Merged
merged 3 commits into from
Jan 27, 2021
Merged

Conversation

dmarteau
Copy link
Contributor

@dmarteau dmarteau commented Jan 19, 2021

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

This PR add more bridge functions to gdal::spatial_ref::srs::SpatialRef implementation.

Struct added

  • AreaOfUse

Type alias

  • AxisOrientationType

Functions added:

  • get_name
  • get_angular_units
  • get_angular_units_name
  • get_linear_units
  • get_linear_units_name
  • is_geographic
  • is_derived_geographic
  • is_local
  • is_projected
  • is_compound
  • is_geocentric
  • is_vertical
  • get_axis_orientation
  • get_axis_name
  • get_axes_count
  • get_area_of_use

Added tests.

@dmarteau dmarteau force-pushed the update_spatial_ref branch 10 times, most recently from 7a81851 to b140f7c Compare January 21, 2021 18:34
CHANGES.md Outdated
@@ -1,5 +1,8 @@
# Changes

## unreleased
* Add more functions to SpatialRef implementation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's already an Unreleased heading, you can add this new item beneath it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Ok(_string(c_ptr))
}

pub fn get_angular_units(&self) -> f64 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I want to get both the name and value I need to make two calls like this right?

let name = srs.get_angular_units_name();
let value = srs.get_angular_units();

Alternatively, you could consider making the api something like:

let (name, value) = srs.get_angular_units()
let name = srs.get_angular_units_name();
let value = srs.get_angular_units_value();

(I don't have any authority in whether or not this gets merged, I'm just a gdal crate user that watches PR's come by)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uh well i guess both ways are fine. I would suggest to keep it this way to avoid mixing Results.

Copy link
Contributor Author

@dmarteau dmarteau Jan 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It tooks me some time to end up with this solution but many of the use case I have faced up involved returning either only the name or only the value for calculation, since returning the name implies allocation it considered that it was better to have a zero cost way to get the units factor value (note: this is also the choice of the python bindings).


pub fn get_axis_orientation(&self, target_key: &str, axis: i32) -> AxisOrientationType {
// We can almost safely assume that if we fail to build a CString then the input
// is not a valide key.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an Option/Result type? Or is it reasonable for users to infer that an error occurred when they get gdal_sys::OGRAxisOrientation::OAO_Other?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right is should be a result type. The GDAL docs state that it will return " the name of the axis or NULL on failure. "

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was not obvious to me since "No CPLError is issued on routine failures (such as not finding the AXIS)".

The error would then be a 'AxisNotFound' error value ?
In this case get_axis_name should also return a Result too not an Option<String> imho,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to Result return type for both get_axis_orientation and get_axis_name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great thanks 👍

@jdroenner
Copy link
Member

Thank you @michaelkirk for reviewing and of cause thanks @dmarteau for the contribution. I have a lot to do at the moment so sometimes there is just no time for more code reviews.

@jdroenner jdroenner merged commit b43596c into georust:master Jan 27, 2021
@michaelkirk michaelkirk mentioned this pull request Jan 27, 2021
2 tasks
@dmarteau dmarteau deleted the update_spatial_ref branch January 27, 2021 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants