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 transform_bounds to wrap proj_trans_bounds #155

Merged
merged 3 commits into from
Jun 9, 2023

Conversation

kylebarron
Copy link
Member

This adds a wrapper of transform_bounds, similar to pyproj's transform_bounds (docs, code).

This also adds a quick doctest, which is derived from one of the above doctests, but which I ran in pyproj to get the output data to compare against.

from pyproj import CRS, Transformer
start = CRS("EPSG:2230")
end = CRS("EPSG:26946")
transformer = Transformer.from_crs(start, end, always_xy=True)
transformer.transform_bounds(4760096.421921, 3744293.729449, 4760196.421921, 3744393.729449)
# (1450880.2910605017,
#  1141263.0111604768,
#  1450910.7711214642,
#  1141293.4912214405)

Questions:

  • Should this handle radians/degrees like pyproj is doing?

Copy link
Member

@michaelkirk michaelkirk left a comment

Choose a reason for hiding this comment

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

Thanks!

Just some small doc nits and some thinking out loud...

I'll wait a couple days before merging in case someone else wants to take a look.

src/proj.rs Outdated
///
/// ```rust
/// # use approx::assert_relative_eq;
/// extern crate proj;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need this extern declaration since some years ago.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed this extern crate as well as a couple others in docstrings

bottom: F,
right: F,
top: F,
densify_pts: i32,
Copy link
Member

Choose a reason for hiding this comment

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

A doc about densify pts would be nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a sentence taken from the pyproj docs

right: F,
top: F,
densify_pts: i32,
) -> Result<[F; 4], ProjError>
Copy link
Member

@michaelkirk michaelkirk Mar 22, 2023

Choose a reason for hiding this comment

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

Though it's pretty much just like pyproj does, it seems a little strange to me that the input and output formats are different. (left, bottom, right, top) -> [F; 4]

We could do like we did with transform and accept some kind of Bounds trait.

Or we could output a bespoke Bounds { left, bottom, right, top }struct (or maybe reuse/consolidate with the existing proj::Area).

One thing I considered, if we did go the Bounds trait route, it'd be natural to want to do:

impl proj::Bounds for geo_types::Rect {
...
}

... but I think that might give us some incorrect results when we span the prime meridian - with how you have it now, it's no problem if left > right. I'm not actually sure what happens if you try it though.

Or we can just leave it. Apparently it's good enough for pyproj.

Copy link
Member Author

Choose a reason for hiding this comment

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

it seems a little strange to me that the input and output formats are different

That's fair. Open to change it to return a tuple of F or use a struct. I'm not too familiar with existing crate conventions.

when we span the prime meridian

It looks like proj allows the max value to be less than the min when it spans the antimeridian.

https://github.com/OSGeo/PROJ/blob/04615b8dbe9c6da65e6898255adeda16dd907ddc/src/4D_api.cpp#L1536-L1537

@michaelkirk
Copy link
Member

Should this handle radians/degrees like pyproj is doing?

I've not used pyproj, but upon quickly reviewing the documentation I haven't found what this refers to. Can you clarify?

@michaelkirk
Copy link
Member

Sorry, I was looking at the wrong docs, instead of the ones you helpfully linked. 🤦

So it looks like the pyproj function takes a radians argument (default False) which when set to True will interpret your input as radians rather than degrees.

I prefer how you have it: assuming degrees only for now.

If we eventually wanted to support radians in the proj crate, it seems like it might have ramifications in Proj/ProjBuilder (e.g.).

Regardless, I'd say it's fine (desirable even) to leave it as degrees only for now.

@michaelkirk
Copy link
Member

I'll wait a couple days months before merging in case someone else wants to take a look.

wow how time flies, sorry!

bors r+

bors bot added a commit that referenced this pull request Jun 6, 2023
155: Add `transform_bounds` to wrap `proj_trans_bounds` r=michaelkirk a=kylebarron

This adds a wrapper of `transform_bounds`, similar to pyproj's `transform_bounds` ([docs](https://pyproj4.github.io/pyproj/stable/api/proj.html#pyproj.Proj.transform_bounds), [code](https://github.com/pyproj4/pyproj/blob/79a8602a2b0b50bf72c072b5a31317570bbdf550/pyproj/_transformer.pyx#L935-L1018)). 

This also adds a quick doctest, which is derived from one of the above doctests, but which I ran in pyproj to get the output data to compare against.
```py
from pyproj import CRS, Transformer
start = CRS("EPSG:2230")
end = CRS("EPSG:26946")
transformer = Transformer.from_crs(start, end, always_xy=True)
transformer.transform_bounds(4760096.421921, 3744293.729449, 4760196.421921, 3744393.729449)
# (1450880.2910605017,
#  1141263.0111604768,
#  1450910.7711214642,
#  1141293.4912214405)
```

Questions:

- Should this handle radians/degrees like pyproj is doing?

Co-authored-by: Kyle Barron <kylebarron2@gmail.com>
@bors
Copy link
Contributor

bors bot commented Jun 6, 2023

Build failed:

@kylebarron
Copy link
Member Author

kylebarron commented Jun 7, 2023

No worries! It looks like the ci failure is unrelated?

@michaelkirk
Copy link
Member

michaelkirk commented Jun 8, 2023 via email

@michaelkirk
Copy link
Member

Ok, once #160 is merged we can retry.

@michaelkirk
Copy link
Member

bors retry

@bors
Copy link
Contributor

bors bot commented Jun 9, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

  • ci result

@bors bors bot merged commit 4304e3b into georust:main Jun 9, 2023
@kylebarron
Copy link
Member Author

Thanks!

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