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

Last change on this file since 9560 was 9555, checked in by Don-vip, 8 years ago

see #12186 - checkstyle

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