1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.projection.proj;
|
---|
3 |
|
---|
4 | import static java.lang.Math.*;
|
---|
5 |
|
---|
6 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.data.projection.Ellipsoid;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * Implementation of the Lambert Conformal Conic projection.
|
---|
12 | *
|
---|
13 | * @author Pieren
|
---|
14 | */
|
---|
15 | public class LambertConformalConic implements Proj {
|
---|
16 |
|
---|
17 | protected Ellipsoid ellps;
|
---|
18 | protected double e;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * projection exponent
|
---|
22 | */
|
---|
23 | protected double n;
|
---|
24 | /**
|
---|
25 | * projection factor
|
---|
26 | */
|
---|
27 | protected double F;
|
---|
28 | /**
|
---|
29 | * radius of the parallel of latitude of the false origin (2SP) or at
|
---|
30 | * natural origin (1SP)
|
---|
31 | */
|
---|
32 | protected double r0;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * precision in iterative schema
|
---|
36 | */
|
---|
37 | protected static final double epsilon = 1e-12;
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Constructor.
|
---|
41 | * Call one of the updateParameters... methods for initialization.
|
---|
42 | */
|
---|
43 | public LambertConformalConic() {
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Initialize for LCC with 2 standard parallels.
|
---|
48 | *
|
---|
49 | * @param ellps the ellipsoid
|
---|
50 | * @param lat_0 latitude of false origin (in degrees)
|
---|
51 | * @param lat_1 latitude of first standard parallel (in degrees)
|
---|
52 | * @param lat_2 latitude of second standard parallel (in degrees)
|
---|
53 | */
|
---|
54 | public void updateParameters2SP(Ellipsoid ellps, double lat_0, double lat_1, double lat_2) {
|
---|
55 | this.ellps = ellps;
|
---|
56 | this.e = ellps.e;
|
---|
57 |
|
---|
58 | final double m1 = m(toRadians(lat_1));
|
---|
59 | final double m2 = m(toRadians(lat_2));
|
---|
60 |
|
---|
61 | final double t1 = t(toRadians(lat_1));
|
---|
62 | final double t2 = t(toRadians(lat_2));
|
---|
63 | final double tf = t(toRadians(lat_0));
|
---|
64 |
|
---|
65 | n = (log(m1) - log(m2)) / (log(t1) - log(t2));
|
---|
66 | F = m1 / (n * pow(t1, n));
|
---|
67 | r0 = F * pow(tf, n);
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Initialize for LCC with 1 standard parallel.
|
---|
72 | *
|
---|
73 | * @param ellps the ellipsoid
|
---|
74 | * @param lat_0 latitude of natural origin (in degrees)
|
---|
75 | */
|
---|
76 | public void updateParameters1SP(Ellipsoid ellps, double lat_0) {
|
---|
77 | this.ellps = ellps;
|
---|
78 | this.e = ellps.e;
|
---|
79 | final double lat_0_rad = toRadians(lat_0);
|
---|
80 |
|
---|
81 | final double m0 = m(lat_0_rad);
|
---|
82 | final double t0 = t(lat_0_rad);
|
---|
83 |
|
---|
84 | n = sin(lat_0_rad);
|
---|
85 | F = m0 / (n * pow(t0, n));
|
---|
86 | r0 = F * pow(t0, n);
|
---|
87 | }
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Initialize LCC by providing the projection parameters directly.
|
---|
91 | *
|
---|
92 | * @param ellps the ellipsoid
|
---|
93 | * @param n see field n
|
---|
94 | * @param F see field F
|
---|
95 | * @param r0 see field r0
|
---|
96 | */
|
---|
97 | public void updateParametersDirect(Ellipsoid ellps, double n, double F, double r0) {
|
---|
98 | this.ellps = ellps;
|
---|
99 | this.e = ellps.e;
|
---|
100 | this.n = n;
|
---|
101 | this.F = F;
|
---|
102 | this.r0 = r0;
|
---|
103 | }
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * auxiliary function t
|
---|
107 | */
|
---|
108 | protected double t(double lat_rad) {
|
---|
109 | return tan(PI/4 - lat_rad / 2.0)
|
---|
110 | / pow(( (1.0 - e * sin(lat_rad)) / (1.0 + e * sin(lat_rad))) , e/2);
|
---|
111 | }
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * auxiliary function m
|
---|
115 | */
|
---|
116 | protected double m(double lat_rad) {
|
---|
117 | return cos(lat_rad) / (sqrt(1 - e * e * pow(sin(lat_rad), 2)));
|
---|
118 | }
|
---|
119 |
|
---|
120 | @Override
|
---|
121 | public String getName() {
|
---|
122 | return tr("Lambert Conformal Conic");
|
---|
123 | }
|
---|
124 |
|
---|
125 | @Override
|
---|
126 | public String getProj4Id() {
|
---|
127 | return "lcc";
|
---|
128 | }
|
---|
129 |
|
---|
130 | @Override
|
---|
131 | public double[] project(double phi, double lambda) {
|
---|
132 | double sinphi = sin(phi);
|
---|
133 | double L = (0.5*log((1+sinphi)/(1-sinphi))) - e/2*log((1+e*sinphi)/(1-e*sinphi));
|
---|
134 | double r = F*exp(-n*L);
|
---|
135 | double gamma = n*lambda;
|
---|
136 | double X = r*sin(gamma);
|
---|
137 | double Y = r0 - r*cos(gamma);
|
---|
138 | return new double[] { X, Y };
|
---|
139 | }
|
---|
140 |
|
---|
141 | @Override
|
---|
142 | public double[] invproject(double east, double north) {
|
---|
143 | double r = sqrt(pow(east,2) + pow(north-r0, 2));
|
---|
144 | double gamma = atan(east / (r0-north));
|
---|
145 | double lambda = gamma/n;
|
---|
146 | double latIso = (-1/n) * log(abs(r/F));
|
---|
147 | double phi = ellps.latitude(latIso, e, epsilon);
|
---|
148 | return new double[] { phi, lambda };
|
---|
149 | }
|
---|
150 |
|
---|
151 | }
|
---|