-
Notifications
You must be signed in to change notification settings - Fork 94
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
Allow to transform ogr geometries to other SRS #29
Conversation
Have time to review this @jdroenner? If not, I can |
I will look into it tomorrow. |
Sure, you can count on it! (today or tomorrow as well) |
I updated the code of this PR following your latests changes regarding error handling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. There are three small issues. I guess they are caused by copy & paste? ;)
One test fails for me with GDAL 2.x :(
---- spatial_ref::tests::transform_ogr_geometry stdout ----
thread 'spatial_ref::tests::transform_ogr_geometry' panicked at 'assertion failed: (left == right)
(left: "POLYGON ((5509543.15080969966948 1716062.191619222285226,5467122.000330002047122 1980151.204280242323875,5623571.028492721728981 2010213.31025367998518,5671834.921544362790883 1746968.078280256595463,5509543.15080969966948 1716062.191619222285226))"
, right: "POLYGON ((5509543.1508097 1716062.19161922,5467122.00033 1980151.20428024,5623571.02849272 2010213.31025368,5671834.92154436 1746968.07828026,5509543.1508097 1716062.19161922))"
)', src/spatial_ref/tests.rs:59
let mut c_wkt: *const c_char = ptr::null_mut(); | ||
let _err = unsafe { osr::OSRExportToWkt(self.0, &mut c_wkt) }; | ||
if _err != ogr_enums::OGRErr::OGRERR_NONE { | ||
Err(ErrorKind::OgrError(_err, "OSRImportFromProj4").into()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method name of the error should be "OSRExportToWkt".
let mut c_wkt: *const c_char = ptr::null_mut(); | ||
let _err = unsafe { osr::OSRExportToPrettyWkt(self.0, &mut c_wkt, false as c_int) }; | ||
if _err != ogr_enums::OGRErr::OGRERR_NONE { | ||
Err(ErrorKind::OgrError(_err, "OSRImportFromProj4").into()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"OSRExportToPrettyWkt"
let mut c_proj4str: *const c_char = ptr::null_mut(); | ||
let _err = unsafe { osr::OSRExportToProj4(self.0, &mut c_proj4str) }; | ||
if _err != ogr_enums::OGRErr::OGRERR_NONE { | ||
Err(ErrorKind::OgrError(_err, "OSRImportFromProj4").into()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"OSRExportToProj4"
…ats + allow to morph to esri format
Oops! Is it so obvious for the copy-paste ;) ? These 3 issues are fixed by my last commit. If you don't mind I also wrapped the About the failing test, maybe we shouldn't rely on the geometry wkt representation (or not directly like that) to check that the geometry was transformed ? (as it is more an issue of coordinate precision (i'm on a 32bits laptop so I don't have either exactly the same values than the one I set for travis..) and the precision seems to be fixed with gdal > 2.0) |
@@ -65,19 +65,25 @@ impl PartialEq for SpatialRef { | |||
} | |||
|
|||
impl SpatialRef { | |||
pub fn new() -> SpatialRef { | |||
pub fn new(definition: &str) -> Result<SpatialRef> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no use-case for new()
without parameters? Maybe the wrapped OSRSetFromUserInput
should be a separate method like new_from_definition(definition: &str)
or something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, there is use-cases for new()
without parameters (I did this as a shortcut as currently the other exposed functions only allow to "import" a SRS, but it might be better to keep a method to create an empty Spatial Reference).
As you advised, it keeps now a new()
method to create a spatial reference without parameters and a new_from_definition()
using OSRSetFromUserInput
.
Ok(SpatialRef(c_obj)) | ||
} | ||
|
||
pub fn new_from_definition(definition: &str) -> Result<SpatialRef> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a big deal, but if you wanted to match the conventions in std
, this would be renamed from new_from_definition
to from_definition
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I didn't know (but it clearly makes sense).
I guess it also apply to from_wkt
, from_epsg
and from_proj4
?
I will rename theses functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To back up my previous comment, you can see some examples here:
https://doc.rust-lang.org/std/?search=from
(scroll down below the from
method/function names)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed a significant list, thx (by looking around i also came across the RFC 430 which mention this from_some_other_type
kind of constructor).
I merged this with master. @mthh thanks again for your contribution :) |
Hi!
Thanks for providing an access to GDAL/OGR api in rust!
I was interested to transform ogr geometries to an other SRS so I wrapped some functions of the OGR spatial reference part of the gdal api (in order to be able to use OGRSpatialReferenceH and OGRCoordinateTransformationH types from C in rust).
It only uses a few major functions, as my main objective was simply to do something like :
Could you be interested to merge these changes ? It also includes a simple example and some tests.
Also don't hesitate to tell me if there is some modifications requested in order to merge this (i'm not really experienced in rust) or if there is some other features of that API that you think should be wrapped.
Cheers!