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

Expose PROJ parameter +gamma for Oblique Mercator #2286

Open
Jeitan opened this issue Nov 14, 2023 · 4 comments
Open

Expose PROJ parameter +gamma for Oblique Mercator #2286

Jeitan opened this issue Nov 14, 2023 · 4 comments

Comments

@Jeitan
Copy link
Contributor

Jeitan commented Nov 14, 2023

Description

I was/am super happy to see the Oblique Mercator projection in Cartopy as of 0.22, because I have had need of it for a while! So I guess now the reward is I have an additional feature request.

I've actually wanted to have the ability to use it with a still-rotated resulting projection (such that it does not force north to be up). Not being very familiar with PROJ, it took me longer than I care to admit to figure out that all I really needed to do was make a coordinate system with "+gamma" set to 0 (or, it turns out after more testing, 180).

I've written my own sub-class of Projection that looks just like the Oblique Mercator class in crs.py, except am able to pass in gamma (RotatedObliqueMercator), and it seems to work very nicely in my (albeit very limited) test cases. However, it would be much easier to just have gamma exposed as an input parameter in the built-in class. It could be defaulted to match alpha to maintain any backward compatibility (which is what I think PROJ does if gamma is not given, if I'm reading the documentation correctly).

My only hesitation is potentially anything weird coming from it pulling its limits from Mercator ... but so far that hasn't been an issue (again, limited test cases).

It does seem like this is something that at least a few people are interested in.
I've made an answer to this (admittedly old) question on GIS stack exchange ... not directly relevant to UTM but accomplishes the desired task:
https://gis.stackexchange.com/questions/429513/how-to-produce-a-cartopy-map-in-utm-with-north-east-up

It would also address this question on StackOverflow (the current answer does work but it involves figuring out the location of a new pole which is annoying)
https://stackoverflow.com/questions/71027066/with-cartopy-can-a-local-map-be-rotated-so-that-north-points-in-an-arbitrary-di

It seems like the ramifications would be pretty small, but key for people like me who want that rotation.

@greglucas
Copy link
Contributor

Seems reasonable to expose that keyword argument if you'd find it helpful.
https://proj.org/en/9.3/operations/projections/omerc.html

@trexfeathers added this in #2096 so they might have thoughts/opinions on it as well.

@trexfeathers
Copy link
Contributor

trexfeathers commented Nov 16, 2023

@trexfeathers added this in #2096 so they might have thoughts/opinions on it as well.

I implemented this based on some example files from CORDEX, which use the basic parameters that you see in the Cartopy class. As @Jeitan says, it seems fairly obvious how things would work if the 'alternative' Proj parameters were used, would just need a bit more logic inside the class.

Any decisions about class design were NOT made from a strongly knowledgeable/opinionated position - I was just seeing what worked. If you need to undo anything to expand the functionality, go ahead 👍

@Jeitan
Copy link
Contributor Author

Jeitan commented Nov 16, 2023

@greglucas @trexfeathers Yay, thank you! I'm glad you are considering it!

One thing I have noticed is that there does appear to be a funny branch cut in PROJ (for the Oblique Mercator specifically), or perhaps I'm mis-reading the documentation. The docs specify limits on gamma but only when not also providing alpha. When I set gamma to 0 but alpha to anything with abs() > 90, it does a weird fliperoo. To get a smooth rotation, say in the counterclockwise direction by specifying positive alpha, from 85 to 90 to 95, I have to set alpha to 85, 90, -95 and gamma to 0, 0, 180. The same thing happens in northern and southern hemisphere. I don't know if Cartopy wants to deal with it, though, since it's a PROJ phenomenon.

To me personally, I'd be fine just passing through gamma, just figured I'd mention it.

@dopplershift
Copy link
Contributor

I think it'd be fine to just plumb in the gamma parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants