locationtech / proj4j

Java port of the Proj.4 library for coordinate reprojection
Other
181 stars 71 forks source link

Support for polar stereographic with alternate scales #106

Open gwlucastrig opened 7 months ago

gwlucastrig commented 7 months ago

I wasn't able to find user-discussions on the web, so I am posting this question as an issue.

I wish to access a data set built on the polar stereographic with scale set to be true at 75 north. Although it looks like the StereographicAzimuthalProjection class has support (undocumented) for the Universal Polar Stereographic projection (UPS). The UPS has a true scale at about 81.11 N, so it doesn't quite fit my requirements. I suppose I could do a hack, but I was wondering if there was a better way to proceed.

pomadchin commented 7 months ago

Hi @gwlucastrig, I'd be happy to help you with whatever approach. Making a PR could be a good starting point, if you have a need why not to try to get it fixed!

gwlucastrig commented 7 months ago

Thanks. I'll take a look at the math and see how it fits within the existing code framework. I would want to make sure I could do something consistent with what you've already got. If I can do that, I'll submit a PR.

gwlucastrig commented 7 months ago

I found the solution, no code changes required. The StereographicAzimuthalProjection has methods called setTrueScaleLatitude() and setTrueScaleLatitudeDegrees() that can be used to set the latitude at which the map scale will be true (1.0). Since the latitude at which I needed for the scale to be true was 75 degrees north, I used the following:

    Datum datum = Datum.WGS84;
    Ellipsoid ellipsoid = datum.getEllipsoid();
    StereographicAzimuthalProjection p = new StereographicAzimuthalProjection(Math.PI / 2, 0);
    p.setEllipsoid(ellipsoid);
    p.setTrueScaleLatitudeDegrees(75.0);
    p.initialize();

This does have the effect of making calls to initialize multiple times (it's called inside the constructor and by the application code), but it gets the job done. Incidentally, the latitude of true scale for Universal Polar Stereographic is approximately 81.11451786859362545 (Wikipedia). So I tested this approach by modifying my program to take that as the argument for setTrueScaleLatitudeDegrees() and comparing it to the results I got when using the setupUps() method provided by the projection class.

Unless you want additional information, I intend to close this issue.

gwlucastrig commented 7 months ago

Incidentally, I notice that in Registry.java, there is an entry for Universal Transverse Mercator (UTM), but the one for Universal Polar Stereographic (UPS) is a commented-out placeholder. It would be straightforward to write a class for UPS derived from StereographicAzimuthalProjection with the appropriate constructor.