001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.coordsys.impl;
034:
035: import com.vividsolutions.jump.coordsys.*;
036: import com.vividsolutions.jump.coordsys.Geographic;
037: import com.vividsolutions.jump.coordsys.Planar;
038:
039: /**
040: * This class implements the Mercator projection.
041: *
042: * @version $Revision: 4 $
043: * @author $Author: javamap $
044: *
045: * <pre>
046: * $Id: Mercator.java 4 2005-06-16 15:27:48Z javamap $
047: * $Date: 2005-06-16 08:27:48 -0700 (Thu, 16 Jun 2005) $
048:
049: * $Log$
050: * Revision 1.1 2005/06/16 15:25:29 javamap
051: * *** empty log message ***
052: *
053: * Revision 1.2 2005/05/03 15:23:55 javamap
054: * *** empty log message ***
055: *
056: * Revision 1.2 2003/11/05 05:12:52 dkim
057: * Added global header; cleaned up Javadoc.
058: *
059: * Revision 1.1 2003/09/15 20:26:12 jaquino
060: * Reprojection
061: *
062: * Revision 1.2 2003/07/25 17:01:04 gkostadinov
063: * Moved classses reponsible for performing the basic projection to a new
064: * package -- base.
065: *
066: * Revision 1.1 2003/07/24 23:14:44 gkostadinov
067: * adding base projection classes
068: *
069: * Revision 1.1 2003/06/20 18:34:31 gkostadinov
070: * Entering the source code into the CVS.
071: * </pre>
072: *
073: */
074:
075: public class Mercator extends Projection {
076:
077: double L0;// central meridian
078: double X0;// false Easting
079: double Y0;// false Northing
080: Geographic q = new Geographic();
081:
082: public Mercator() {
083: super ();
084: }
085:
086: /**
087: *@param centralMeridian in degrees
088: *@param falseEasting in metres
089: *@param falseNorthing in metres
090: */
091: public void setParameters(double centralMeridian,
092: double falseEasting, double falseNorthing) {
093: L0 = centralMeridian / 180.0 * Math.PI;
094: X0 = falseEasting;
095: Y0 = falseNorthing;
096: }
097:
098: public Planar asPlanar(Geographic q0, Planar p) {
099: q.lat = q0.lat / 180.0 * Math.PI;
100: q.lon = q0.lon / 180.0 * Math.PI;
101: forward(q, p);
102: return p;
103: }
104:
105: public Geographic asGeographic(Planar p, Geographic q) {
106: inverse(p, q);
107: q.lat = q.lat * 180.0 / Math.PI;
108: q.lon = q.lon * 180.0 / Math.PI;
109: return q;
110: }
111:
112: void forward(Geographic q, Planar p) {
113: double a;
114: double e;
115: a = currentSpheroid.getA();
116: e = currentSpheroid.getE();
117: p.x = a * (q.lon - L0);
118: p.y = (a / 2.0)
119: * Math.log(((1.0 + Math.sin(q.lat)) / (1.0 - Math
120: .sin(q.lat)))
121: * Math.pow(
122: ((1.0 - e * Math.sin(q.lat)) / (1.0 + e
123: * Math.sin(q.lat))), e));
124: }
125:
126: void inverse(Planar p, Geographic q) {
127: double t;
128: double delta;
129: double phiI;
130: double phi;
131: double lambda;
132: double a;
133: double e;
134: a = currentSpheroid.getA();
135: e = currentSpheroid.getE();
136: t = Math.exp(-p.y / a);
137: //phi = Math.PI / 2.0 - 2.0 * Math.tan(t); -- transcription error
138: phi = Math.PI / 2.0 - 2.0 * Math.atan(t);
139: delta = 10000.0;
140: do {
141: phiI = Math.PI
142: / 2.0
143: - 2.0
144: * Math
145: .atan(t
146: * Math.pow(((1.0 - e
147: * Math.sin(phi)) / (1.0 + e
148: * Math.sin(phi))),
149: (e / 2.0)));
150: delta = Math.abs(phiI - phi);
151: phi = phiI;
152: } while (delta > 1.0e-014);
153: lambda = p.x / a + L0;
154: q.lat = phi;
155: q.lon = lambda;
156: }
157:
158: }
|