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

Last change on this file since 13601 was 12013, checked in by bastiK, 7 years ago

see #11889 - backport improved version of Math.toDegrees and Math.toRadians from Java 9

  • Property svn:eol-style set to native
File size: 3.7 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 * Contants used for the forward and inverse transform for the eliptical
36 * case of the Cassini-Soldner.
37 */
38 private static final double C1 = 0.16666666666666666666;
39 private static final double C2 = 0.008333333333333333333;
40 private static final double C3 = 0.041666666666666666666;
41 private static final double C4 = 0.33333333333333333333;
42 private static final double C5 = 0.066666666666666666666;
43
44 @Override
45 public String getName() {
46 return tr("Cassini-Soldner");
47 }
48
49 @Override
50 public String getProj4Id() {
51 return "cass";
52 }
53
54 @Override
55 public void initialize(ProjParameters params) throws ProjectionConfigurationException {
56 super.initialize(params);
57 if (params.lat0 == null)
58 throw new ProjectionConfigurationException(tr("Parameter ''{0}'' required.", "lat_0"));
59 double latitudeOfOrigin = Utils.toRadians(params.lat0);
60 ml0 = mlfn(latitudeOfOrigin, Math.sin(latitudeOfOrigin), Math.cos(latitudeOfOrigin));
61 }
62
63 @Override
64 public double[] project(double phi, double lam) {
65 double sinphi = Math.sin(phi);
66 double cosphi = Math.cos(phi);
67
68 double n = 1.0 / (Math.sqrt(1.0 - e2 * sinphi * sinphi));
69 double tn = Math.tan(phi);
70 double t = tn * tn;
71 double a1 = lam * cosphi;
72 double c = cosphi * cosphi * e2 / (1 - e2);
73 double a2 = a1 * a1;
74
75 double x = n * a1 * (1.0 - a2 * t * (C1 - (8.0 - t + 8.0 * c) * a2 * C2));
76 double y = mlfn(phi, sinphi, cosphi) - ml0 + n * tn * a2 * (0.5 + (5.0 - t + 6.0 * c) * a2 * C3);
77 return new double[] {x, y};
78 }
79
80 @Override
81 public double[] invproject(double x, double y) {
82 double ph1 = invMlfn(ml0 + y);
83 double tn = Math.tan(ph1);
84 double t = tn * tn;
85 double n = Math.sin(ph1);
86 double r = 1.0 / (1.0 - e2 * n * n);
87 n = Math.sqrt(r);
88 r *= (1.0 - e2) * n;
89 double dd = x / n;
90 double d2 = dd * dd;
91 double phi = ph1 - (n * tn / r) * d2 * (0.5 - (1.0 + 3.0 * t) * d2 * C3);
92 double lam = dd * (1.0 + t * d2 * (-C4 + (1.0 + 3.0 * t) * d2 * C5)) / Math.cos(ph1);
93 return new double[] {phi, lam};
94 }
95
96 @Override
97 public Bounds getAlgorithmBounds() {
98 return new Bounds(-89, -1.0, 89, 1.0, false);
99 }
100}
Note: See TracBrowser for help on using the repository browser.