source: josm/trunk/src/org/openstreetmap/josm/data/projection/proj/Mercator.java@ 10748

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

Checkstyle 6.19: enable SingleSpaceSeparator and fix violations

  • Property svn:eol-style set to native
File size: 4.4 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 * Mercator Cylindrical Projection. The parallels and the meridians are straight lines and
11 * cross at right angles; this projection thus produces rectangular charts. The scale is true
12 * along the equator (by default) or along two parallels equidistant of the equator (if a scale
13 * factor other than 1 is used). This projection is used to represent areas close to the equator.
14 * It is also often used for maritime navigation because all the straight lines on the chart are
15 * <em>loxodrome</em> lines, i.e. a ship following this line would keep a constant azimuth on its
16 * compass.
17 * <p>
18 * This implementation handles both the 1 and 2 stardard parallel cases.
19 * For 1 SP (EPSG code 9804), the line of contact is the equator.
20 * For 2 SP (EPSG code 9805) lines of contact are symmetrical
21 * about the equator.
22 * <p>
23 * This class has been derived from the implementation of the Geotools project;
24 * git 8cbf52d, org.geotools.referencing.operation.projection.Mercator
25 * at the time of migration.
26 * <p>
27 * <b>References:</b>
28 * <ul>
29 * <li>John P. Snyder (Map Projections - A Working Manual,<br>
30 * U.S. Geological Survey Professional Paper 1395, 1987)</li>
31 * <li>"Coordinate Conversions and Transformations including Formulas",<br>
32 * EPSG Guidence Note Number 7, Version 19.</li>
33 * </ul>
34 *
35 * @author André Gosselin
36 * @author Martin Desruisseaux (PMO, IRD)
37 * @author Rueben Schulz
38 * @author Simone Giannecchini
39 *
40 * @see <A HREF="http://mathworld.wolfram.com/MercatorProjection.html">Mercator projection on MathWorld</A>
41 * @see <A HREF="http://www.remotesensing.org/geotiff/proj_list/mercator_1sp.html">"mercator_1sp" on RemoteSensing.org</A>
42 * @see <A HREF="http://www.remotesensing.org/geotiff/proj_list/mercator_2sp.html">"mercator_2sp" on RemoteSensing.org</A>
43 */
44public class Mercator extends AbstractProj implements IScaleFactorProvider {
45 /**
46 * Maximum difference allowed when comparing real numbers.
47 */
48 private static final double EPSILON = 1E-6;
49
50 protected double scaleFactor;
51
52 @Override
53 public String getName() {
54 return tr("Mercator");
55 }
56
57 @Override
58 public String getProj4Id() {
59 return "merc";
60 }
61
62 @Override
63 public void initialize(ProjParameters params) throws ProjectionConfigurationException {
64 super.initialize(params);
65 scaleFactor = 1;
66 if (params.lat_ts != null) {
67 /*
68 * scaleFactor is not a parameter in the 2 SP case and is computed from
69 * the standard parallel.
70 */
71 double standardParallel = Math.toRadians(params.lat_ts);
72 if (spherical) {
73 scaleFactor *= Math.cos(standardParallel);
74 } else {
75 scaleFactor *= msfn(Math.sin(standardParallel), Math.cos(standardParallel));
76 }
77 }
78 /*
79 * A correction that allows us to employs a latitude of origin that is not
80 * correspondent to the equator. See Snyder and al. for reference, page 47.
81 */
82 if (params.lat0 != null) {
83 final double lat0 = Math.toRadians(params.lat0);
84 final double sinPhi = Math.sin(lat0);
85 scaleFactor *= (Math.cos(lat0) / (Math.sqrt(1 - e2 * sinPhi * sinPhi)));
86 }
87 }
88
89 @Override
90 public double[] project(double y, double x) {
91 if (Math.abs(y) > (Math.PI/2 - EPSILON)) {
92 return new double[] {0, 0}; // this is an error and should be handled somehow
93 }
94 if (spherical) {
95 y = Math.log(Math.tan(Math.PI/4 + 0.5*y));
96 } else {
97 y = -Math.log(tsfn(y, Math.sin(y)));
98 }
99 return new double[] {x, y};
100 }
101
102 @Override
103 public double[] invproject(double x, double y) {
104 if (spherical) {
105 y = Math.PI/2 - 2.0*Math.atan(Math.exp(-y));
106 } else {
107 y = Math.exp(-y);
108 y = cphi2(y);
109 }
110 return new double[] {y, x};
111 }
112
113 @Override
114 public Bounds getAlgorithmBounds() {
115 return new Bounds(-89, -180, 89, 180, false);
116 }
117
118 @Override
119 public double getScaleFactor() {
120 return scaleFactor;
121 }
122}
Note: See TracBrowser for help on using the repository browser.