source: josm/trunk/src/org/openstreetmap/josm/data/projection/proj/LambertConformalConic.java@ 10001

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

sonar - Local variable and method parameter names should comply with a naming convention

  • Property svn:eol-style set to native
File size: 5.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.projection.proj;
3
4import static java.lang.Math.PI;
5import static java.lang.Math.abs;
6import static java.lang.Math.atan;
7import static java.lang.Math.cos;
8import static java.lang.Math.exp;
9import static java.lang.Math.log;
10import static java.lang.Math.pow;
11import static java.lang.Math.sin;
12import static java.lang.Math.sqrt;
13import static java.lang.Math.tan;
14import static java.lang.Math.toRadians;
15import static org.openstreetmap.josm.tools.I18n.tr;
16
17import org.openstreetmap.josm.data.Bounds;
18import org.openstreetmap.josm.data.projection.CustomProjection.Param;
19import org.openstreetmap.josm.data.projection.Ellipsoid;
20import org.openstreetmap.josm.data.projection.ProjectionConfigurationException;
21
22/**
23 * Implementation of the Lambert Conformal Conic projection.
24 *
25 * @author Pieren
26 */
27public class LambertConformalConic extends AbstractProj {
28
29 protected Ellipsoid ellps;
30
31 public abstract static class Parameters {
32 public final double latitudeOrigin;
33
34 public Parameters(double latitudeOrigin) {
35 this.latitudeOrigin = latitudeOrigin;
36 }
37 }
38
39 public static class Parameters1SP extends Parameters {
40 public Parameters1SP(double latitudeOrigin) {
41 super(latitudeOrigin);
42 }
43 }
44
45 public static class Parameters2SP extends Parameters {
46 public final double standardParallel1;
47 public final double standardParallel2;
48
49 public Parameters2SP(double latitudeOrigin, double standardParallel1, double standardParallel2) {
50 super(latitudeOrigin);
51 this.standardParallel1 = standardParallel1;
52 this.standardParallel2 = standardParallel2;
53 }
54 }
55
56 private Parameters params;
57
58 /**
59 * projection exponent
60 */
61 protected double n;
62 /**
63 * projection factor
64 */
65 protected double f;
66 /**
67 * radius of the parallel of latitude of the false origin (2SP) or at
68 * natural origin (1SP)
69 */
70 protected double r0;
71
72 /**
73 * precision in iterative schema
74 */
75 protected static final double epsilon = 1e-12;
76
77 @Override
78 public void initialize(ProjParameters params) throws ProjectionConfigurationException {
79 super.initialize(params);
80 ellps = params.ellps;
81 if (params.lat0 == null)
82 throw new ProjectionConfigurationException(tr("Parameter ''{0}'' required.", Param.lat_0.key));
83 if (params.lat1 != null && params.lat2 != null) {
84 initialize2SP(params.lat0, params.lat1, params.lat2);
85 } else {
86 initialize1SP(params.lat0);
87 }
88 }
89
90 /**
91 * Initialize for LCC with 2 standard parallels.
92 *
93 * @param lat0 latitude of false origin (in degrees)
94 * @param lat1 latitude of first standard parallel (in degrees)
95 * @param lat2 latitude of second standard parallel (in degrees)
96 */
97 private void initialize2SP(double lat0, double lat1, double lat2) {
98 this.params = new Parameters2SP(lat0, lat1, lat2);
99
100 final double m1 = m(toRadians(lat1));
101 final double m2 = m(toRadians(lat2));
102
103 final double t1 = t(toRadians(lat1));
104 final double t2 = t(toRadians(lat2));
105 final double tf = t(toRadians(lat0));
106
107 n = (log(m1) - log(m2)) / (log(t1) - log(t2));
108 f = m1 / (n * pow(t1, n));
109 r0 = f * pow(tf, n);
110 }
111
112 /**
113 * Initialize for LCC with 1 standard parallel.
114 *
115 * @param lat0 latitude of natural origin (in degrees)
116 */
117 private void initialize1SP(double lat0) {
118 this.params = new Parameters1SP(lat0);
119 final double lat0rad = toRadians(lat0);
120
121 final double m0 = m(lat0rad);
122 final double t0 = t(lat0rad);
123
124 n = sin(lat0rad);
125 f = m0 / (n * pow(t0, n));
126 r0 = f * pow(t0, n);
127 }
128
129 /**
130 * auxiliary function t
131 * @param latRad latitude in radians
132 * @return result
133 */
134 protected double t(double latRad) {
135 return tan(PI/4 - latRad / 2.0)
136 / pow((1.0 - e * sin(latRad)) / (1.0 + e * sin(latRad)), e/2);
137 }
138
139 /**
140 * auxiliary function m
141 * @param latRad latitude in radians
142 * @return result
143 */
144 protected double m(double latRad) {
145 return cos(latRad) / (sqrt(1 - e * e * pow(sin(latRad), 2)));
146 }
147
148 @Override
149 public String getName() {
150 return tr("Lambert Conformal Conic");
151 }
152
153 @Override
154 public String getProj4Id() {
155 return "lcc";
156 }
157
158 @Override
159 public double[] project(double phi, double lambda) {
160 double sinphi = sin(phi);
161 double l = (0.5*log((1+sinphi)/(1-sinphi))) - e/2*log((1+e*sinphi)/(1-e*sinphi));
162 double r = f*exp(-n*l);
163 double gamma = n*lambda;
164 double x = r*sin(gamma);
165 double y = r0 - r*cos(gamma);
166 return new double[] {x, y};
167 }
168
169 @Override
170 public double[] invproject(double east, double north) {
171 double r = sqrt(pow(east, 2) + pow(north-r0, 2));
172 double gamma = atan(east / (r0-north));
173 double lambda = gamma/n;
174 double latIso = (-1/n) * log(abs(r/f));
175 double phi = ellps.latitude(latIso, e, epsilon);
176 return new double[] {phi, lambda};
177 }
178
179 public final Parameters getParameters() {
180 return params;
181 }
182
183 @Override
184 public Bounds getAlgorithmBounds() {
185 double lat;
186 if (params instanceof Parameters2SP) {
187 Parameters2SP p2p = (Parameters2SP) params;
188 lat = (p2p.standardParallel1 + p2p.standardParallel2) / 2;
189 } else {
190 lat = params.latitudeOrigin;
191 }
192 double minlat = Math.max(lat - 60, -89);
193 double maxlat = Math.min(lat + 60, 89);
194 return new Bounds(minlat, -85, maxlat, 85, false);
195 }
196}
Note: See TracBrowser for help on using the repository browser.