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

Implement CoordTransformOptions and CoordTransform::new_with_options constructor #372

Merged
merged 1 commit into from
Mar 7, 2023

Conversation

ttencate
Copy link
Contributor

@ttencate ttencate commented Feb 15, 2023

  • 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.

I only needed this for the ballpark option, because I found it surprising that it's possible by default to transform between CRSes that are only valid on opposite sides of the world. I didn't change this default though.

The other three options are wrapped, but I don't understand them well enough to add tests for them.

@ttencate ttencate force-pushed the feature/coord_transform_options branch 4 times, most recently from 8493ad9 to 08d883b Compare February 15, 2023 21:17
Copy link
Contributor

@metasim metasim left a comment

Choose a reason for hiding this comment

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

A few nits, but overall LGTM. However, I suggest a review from one of the more experienced team members.

src/spatial_ref/srs.rs Outdated Show resolved Hide resolved
src/spatial_ref/srs.rs Outdated Show resolved Hide resolved
src/spatial_ref/srs.rs Outdated Show resolved Hide resolved
src/spatial_ref/srs.rs Outdated Show resolved Hide resolved
///
/// The pipeline may be provided as a PROJ string (single step operation or multiple step
/// string starting with +proj=pipeline), a WKT2 string describing a CoordinateOperation, or a
/// "urn:ogc:def:coordinateOperation:EPSG::XXXX" URN.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a canonical description on these operation definitions you could link to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have absolutely no idea what any of this even means, I just copied the docs from upstream GDAL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found https://gdal.org/tutorials/osr_api_tut.html#advanced-coordinate-transformation which sheds some light. I don't think our API docs are the right place to expand this fully, so I added a link.

let err = trafo.unwrap_err();
assert!(matches!(err, GdalError::NullPointer { .. }), "{:?}", err);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be viable to provide a test for set_coordinate_operation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If somebody could tell me input and expected output, sure. I only implemented it for completeness. If it's not cool to have untested (but also rarely used!) code in there, I'm also happy to remove it again.

Copy link
Member

Choose a reason for hiding this comment

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

I think we could call it just to check it doesn't crash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test.

@ttencate ttencate force-pushed the feature/coord_transform_options branch from 08d883b to 6c3577a Compare February 16, 2023 15:29
@metasim metasim requested review from lnicola and jdroenner February 16, 2023 20:34
src/spatial_ref/srs.rs Outdated Show resolved Hide resolved
)
};
if ret_val == 0 {
return Err(GdalError::OctError {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure how our errors are supposed to work, but this function returns an error message, e.g. Invalid dfWestLongitudeDeg. You can get it using utils::_last_cpl_err, but of course, that will return a CplError instead. So I don't really know what would be the best.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why this OCT prefix is even used here (OGR Coordinate Transformation??), so it seems excessive to add another error type for it. CplError will do fine for now. Used this for the other setters as well, though these are (currently) infallible.

///
/// If this option is specified with PROJ < 8, the `OGR_CT_OP_SELECTION` configuration option
/// will default to `BEST_ACCURACY`.
#[cfg(all(major_ge_3, minor_ge_3))]
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong, it will fail in 4.0. We want major > 3 || major == 3 && minor >= 3. There are some places where we do this correctly.

But honestly, I wish we could improve on these somehow.

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. Yeah, definitely not the only occurrence of this mistake in the codebase, or even in this file.

Merging major and minor into a single gdal_ge_3_3 option would make these lines shorter, at the expense of adding a bunch of (autogenerated) cfg options.

A custom proc macro with custom syntax could of course also work.

src/spatial_ref/srs.rs Outdated Show resolved Hide resolved
src/spatial_ref/srs.rs Outdated Show resolved Hide resolved
@@ -33,6 +175,24 @@ impl CoordTransform {
})
}

pub fn new_ex(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub fn new_ex(
pub fn new_with_options(

?

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, but note that it's inconsistent with Dataset::new_ex. That one was named after GDALOpenEx, however, so there's some argument to be made for the inconsistency.

@ttencate ttencate changed the title Implement CoordTransformOptions and CoordTransform::new_ex constructor Implement CoordTransformOptions and CoordTransform::new_with_options constructor Mar 7, 2023
@ttencate ttencate force-pushed the feature/coord_transform_options branch from 6c3577a to 75bf1d6 Compare March 7, 2023 14:10
@ttencate ttencate force-pushed the feature/coord_transform_options branch from 75bf1d6 to 8c964e0 Compare March 7, 2023 14:13
@ttencate
Copy link
Contributor Author

ttencate commented Mar 7, 2023

Rebased and all comments addressed.

@lnicola
Copy link
Member

lnicola commented Mar 7, 2023

bors r+

@bors bors bot merged commit 7efcc41 into georust:master Mar 7, 2023
@metasim metasim mentioned this pull request May 18, 2023
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