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

Initial conversions support. #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

gibbz00
Copy link
Contributor

@gibbz00 gibbz00 commented Dec 12, 2023

First significant one being axisswap:

use proj4rs::conversions::Conversion;

let conversion = Conversion::from_proj_string("+proj=axisswap +order=2,1").unwrap();
let mut points = (1., 2., 0.);
conversion.convert(&mut points).unwrap();
assert_eq!((2., 1., 0.), points);

@dmarteau
Copy link
Member

First of all , thanks for you interest !

As a matter of fact the proj4rs structure is built using the transformation scheme of proj version 4: which is already a transformation pipeline including geocentric, geodetic, axisswap and unit conversion opérations.
The Proj library added the conversion operations along with pipeline operations, which makes sense in this context since projections are now defined as pipelined operations.

In short, conversions are alreay included in proj4rs.

For example: the specific axis swap conversion could be handled with a latlong transformation (which is basically a noop transformation) and a +axis parameter since proj4rs support the cartographic transformations parameters.

I really want to restrict proj4rs to cartographic transformation for this specific usage: because of his pipeline approach, the Proj library is much more suited for exploring exotic transformations and much complex situations.

@gibbz00
Copy link
Contributor Author

gibbz00 commented May 19, 2024

Hii,

It was quite a while since I worked on this, but I'll make an attempt at explaining the original motivation from memory.

The reason for why I did it this way was because I was using crs_definitions for ready-made Proj strings. Adding a separate conversion felt like a natural way for me to handle the case when the respective spacial references used different axis orders:

pub trait TransformExt: Transform + Sized {
    fn transformed_epsg(&mut self, from: &SpacialReference, to: &SpacialReference) -> Result<(), proj4rs::errors::Error> {
        if from.axes() != to.axes() {
            Conversion::from_proj_string("+proj=axisswap +order=2,1")?.convert(self)?;
        }

        proj4rs::transform::transform(
            &Proj::from_proj_string(from.proj_str())?,
            &Proj::from_proj_string(to.proj_str())?,
            self,
        )
    }
}

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.

2 participants