source: josm/trunk/src/org/openstreetmap/josm/data/projection/proj/CassiniSoldner.java@ 13640

Last change on this file since 13640 was 13632, checked in by Don-vip, 6 years ago

see #16129 - add spherical versions of Cassini and Albers projections

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.projection.proj;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import org.openstreetmap.josm.data.Bounds;
7import org.openstreetmap.josm.data.projection.ProjectionConfigurationException;
8import org.openstreetmap.josm.tools.Utils;
9
10/**
11 * Cassini-Soldner Projection (EPSG code 9806).
12 * The Cassini-Soldner Projection is the ellipsoidal version of the Cassini
13 * projection for the sphere. It is not conformal but as it is relatively simple
14 * to construct it was extensively used in the last century and is still useful
15 * for mapping areas with limited longitudinal extent. It has now largely
16 * been replaced by the conformal Transverse Mercator which it resembles. Like this,
17 * it has a straight central meridian along which the scale is true, all other
18 * meridians and parallels are curved, and the scale distortion increases
19 * rapidly with increasing distance from the central meridian.
20 * <p>
21 *
22 * This class has been derived from the implementation of the Geotools project;
23 * git 8cbf52d, org.geotools.referencing.operation.projection.CassiniSoldner
24 * at the time of migration.
25 */
26public class CassiniSoldner extends AbstractProj {
27
28 /**
29 * Meridian distance at the {@code latitudeOfOrigin}.
30 * Used for calculations for the ellipsoid.
31 */
32 private double ml0;
33
34 /**
35 * Latitude of origin.
36 */
37 private double phi0;
38
39 /**
40 * Constants used for the forward and inverse transform for the elliptical
41 * case of the Cassini-Soldner.
42 */
43 private static final double C1 = 0.16666666666666666666;
44 private static final double C2 = 0.008333333333333333333;
45 private static final double C3 = 0.041666666666666666666;
46 private static final double C4 = 0.33333333333333333333;
47 private static final double C5 = 0.066666666666666666666;
48
49 @Override
50 public String getName() {
51 return tr("Cassini-Soldner");
52 }
53
54 @Override
55 public String getProj4Id() {
56 return "cass";
57 }
58
59 @Override
60 public void initialize(ProjParameters params) throws ProjectionConfigurationException {
61 super.initialize(params);
62 if (params.lat0 == null)
63 throw new ProjectionConfigurationException(tr("Parameter ''{0}'' required.", "lat_0"));
64 phi0 = Utils.toRadians(params.lat0);
65 ml0 = mlfn(phi0, Math.sin(phi0), Math.cos(phi0));
66 }
67
68 @Override
69 public double[] project(double phi, double lam) {
70 if (spherical) {
71 double x = aasin(Math.cos(phi) * Math.sin(lam));
72 double y = Math.atan2(Math.tan(phi), Math.cos(lam));
73 return new double[] {x, y};
74 } else {
75 double sinphi = Math.sin(phi);
76 double cosphi = Math.cos(phi);
77
78 double n = 1.0 / (Math.sqrt(1.0 - e2 * sinphi * sinphi));
79 double tn = Math.tan(phi);
80 double t = tn * tn;
81 double a1 = lam * cosphi;
82 double c = cosphi * cosphi * e2 / (1 - e2);
83 double a2 = a1 * a1;
84
85 double x = n * a1 * (1.0 - a2 * t * (C1 - (8.0 - t + 8.0 * c) * a2 * C2));
86 double y = mlfn(phi, sinphi, cosphi) - ml0 + n * tn * a2 * (0.5 + (5.0 - t + 6.0 * c) * a2 * C3);
87 return new double[] {x, y};
88 }
89 }
90
91 @Override
92 public double[] invproject(double x, double y) {
93 if (spherical) {
94 double dd = y + phi0;
95 double phi = aasin(Math.sin(dd * Math.cos(x)));
96 double lam = Math.atan2(Math.tan(x), Math.cos(dd));
97 return new double[] {phi, lam};
98 } else {
99 double ph1 = invMlfn(ml0 + y);
100 double tn = Math.tan(ph1);
101 double t = tn * tn;
102 double n = Math.sin(ph1);
103 double r = 1.0 / (1.0 - e2 * n * n);
104 n = Math.sqrt(r);
105 r *= (1.0 - e2) * n;
106 double dd = x / n;
107 double d2 = dd * dd;
108 double phi = ph1 - (n * tn / r) * d2 * (0.5 - (1.0 + 3.0 * t) * d2 * C3);
109 double lam = dd * (1.0 + t * d2 * (-C4 + (1.0 + 3.0 * t) * d2 * C5)) / Math.cos(ph1);
110 return new double[] {phi, lam};
111 }
112 }
113
114 @Override
115 public Bounds getAlgorithmBounds() {
116 return new Bounds(-89, -1.0, 89, 1.0, false);
117 }
118}
Note: See TracBrowser for help on using the repository browser.