Skip to content

Conversation

@potion-cellar
Copy link
Contributor

@potion-cellar potion-cellar commented Nov 3, 2025

Resolves #371
Resolves #331

Note:
Maybe not the best way to do the inner forward/inverse -- was difficult to get the inner projection to init() properly (i.e. passing the params correctly) and couldn't find any working examples of such in the code.

Also noted that some projections did not have default values set for some params (despite what the docs say), causing reprojection tests to fail unless init() was modified to set these default params. Could maybe split that off into a separate branch.

Fixed in later commits, text below is no longer relevant:
Tests verify that +x_0 and +y_0 are being passed forward successfully. +R and +lon_0 are also being passed forward but they seem to result in a major divergence of expected coordinates, or at least +lon_0 does. I verified the inner projection was receiving the correct value for this, so not sure if it's a bug with the inner projections or what.

Copy link
Member

@ahocevar ahocevar left a comment

Choose a reason for hiding this comment

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

You mentioned failing tests or unexpected values. Can you please clarify? We don't want to test for incorrect values, so if you modified expected test values to make the tests pass, we should talk about it and make sure we use the same expected values as other libraries.

@potion-cellar
Copy link
Contributor Author

potion-cellar commented Nov 3, 2025

You mentioned failing tests or unexpected values. Can you please clarify? We don't want to test for incorrect values, so if you modified expected test values to make the tests pass, we should talk about it and make sure we use the same expected values as other libraries.

I did not include any tests where the test values are not what they should be (e.g. forcing the tests to past).

However, I don't have any tests for when +lon_0 and +R are being used. I did have tests for the three different rotation methods, in addition to passing +x_0 and +y_0.

Doing some more testing now, seems like +R is fine and it's just lon_0 that is causing problems.

I've added a couple more tests including one that should be failing. That's where the problem is.

I've just modified the code to pass the entire proj4 string to the inner projection, per the original source code. This has not resolved the problem with lon_0. I can see that the inner projection is receiving the correct lon_0 value, and verified that when used on its own (e.g.+proj=moll +lon_0=10 +R=6400000) I can get values I expect when projecting coordinates (so not an implementation issue on the mollweide side, I think).

Neither this code nor the PROJ source code touches lon_0 in either forward or inverse, it's merely passed through as a param to the inner projection, so this is pretty baffling considering I have verified the inner projection is receiving the correct value.

@potion-cellar
Copy link
Contributor Author

@ahocevar Okay, I have it sorted out now. It seems there is a subtle difference in how PROJ handles lon_0. In the proj4js code here I need to manually apply it before/after forward/inverse.

I also adjusted the param parsing to match the original source (order of preference for which transform method), and added a bunch of tests around param parsing.

Here are the tests that have been added, testing against the same string and coordinates in PROJ:

  • forward/inverse for moll, new pole method
  • forward/inverse for moll, rotate about point method
  • forward/inverse for moll, new equator method
  • forward/inverse for moll, new equator method w/ +x_0 and +y_0
  • forward/inverse for moll, new equator method w/ +x_0, +y_0, and +R
  • forward/inverse for moll, new pole method w/ +lon_0 and +R
  • forward/inverse for moll, new pole method w/ +lon_0, +R, +ellps, and +pm
  • some of the above but for eqearth
  • tests for missing param errors, or incomplete param sets for a given method
  • tests for param = NaN errors
  • tests for valid inner projection
  • tests for invalid param value errors (e.g. +o_lat_1=90)

Let me know any further changes!

Copy link
Member

@ahocevar ahocevar left a comment

Choose a reason for hiding this comment

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

Thanks for your continued effort on this, @potion-cellar. Although this implementation is strictly bound to proj strings, without support for WKT or projjson, I'm going to accept and merge this. If someone needs support for this with WKT or projjson, that can be handled in a separate pull request.

@ahocevar ahocevar merged commit 33f8709 into proj4js:master Nov 8, 2025
5 checks passed
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.

How to add new projection? Implement +proj=ob_tran (1000€ bounty)

2 participants