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.jts.util.Assert;
036: import com.vividsolutions.jump.coordsys.*;
037: import com.vividsolutions.jump.coordsys.Geographic;
038: import com.vividsolutions.jump.coordsys.Planar;
039:
040: /**
041: * This class implements the Universal Transverse Mercator Projection.
042:
043: * @version $Revision: 672 $
044: * @author $Author: michaudm $
045: * <pre>
046: * $Id: UniversalTransverseMercator.java 672 2007-04-07 13:17:05Z michaudm $
047: * $Date: 2007-04-07 06:17:05 -0700 (Sat, 07 Apr 2007) $
048: * $Log$
049: * Revision 1.2 2007/04/07 13:17:03 michaudm
050: * 52 javadoc tag warnings fixed
051: *
052: * Revision 1.1 2005/06/16 15:25:29 javamap
053: * *** empty log message ***
054: *
055: * Revision 1.2 2005/05/03 15:23:55 javamap
056: * *** empty log message ***
057: *
058: * Revision 1.2 2003/11/05 05:18:44 dkim
059: * Added global header; cleaned up Javadoc.
060: *
061: * Revision 1.1 2003/09/15 20:26:11 jaquino
062: * Reprojection
063: *
064: * Revision 1.2 2003/07/25 17:01:03 gkostadinov
065: * Moved classses reponsible for performing the basic projection to a new
066: * package -- base.
067: *
068: * Revision 1.1 2003/07/24 23:14:43 gkostadinov
069: * adding base projection classes
070: *
071: * Revision 1.1 2003/06/20 18:34:30 gkostadinov
072: * Entering the source code into the CVS.
073: * </pre>
074: */
075:
076: public class UniversalTransverseMercator extends Projection {
077:
078: private final static double SCALE_FACTOR = 0.9996;
079: private final static double FALSE_EASTING = 500000.0;
080: private final static double FALSE_NORTHING = 0.0;
081:
082: private TransverseMercator transverseMercator = new TransverseMercator();
083:
084: public UniversalTransverseMercator() {
085: }
086:
087: private int zone = -1;
088:
089: /**
090: * @param zone must be between 7 and 11
091: */
092: public void setParameters(int zone) {
093:
094: Assert.isTrue(zone >= 7, "UTM zone " + zone + " not supported");
095: Assert
096: .isTrue(zone <= 11, "UTM zone " + zone
097: + " not supported");
098:
099: switch (zone) {
100: case 7:
101: transverseMercator.setParameters(-141.0);
102: break;
103: case 8:
104: transverseMercator.setParameters(-135.0);
105: break;
106: case 9:
107: transverseMercator.setParameters(-129.0);
108: break;
109: case 10:
110: transverseMercator.setParameters(-123.0);
111: break;
112: case 11:
113: transverseMercator.setParameters(-117.0);
114: break;
115: case 12:
116: transverseMercator.setParameters(-111.0);
117: break;
118: default:
119: Assert.shouldNeverReachHere();
120: }
121: this .zone = zone;
122: }
123:
124: public void setSpheroid(Spheroid s) {
125: transverseMercator.setSpheroid(s);
126: }
127:
128: public Geographic asGeographic(Planar p, Geographic q) {
129:
130: Assert.isTrue(zone != -1, "Call #setParameters first");
131:
132: p.x = (p.x - FALSE_EASTING) / SCALE_FACTOR;
133: p.y = (p.y - FALSE_NORTHING) / SCALE_FACTOR;
134: transverseMercator.asGeographic(p, q);
135: return q;
136: }
137:
138: public Planar asPlanar(Geographic q0, Planar p) {
139:
140: Assert.isTrue(zone != -1, "Call #setParameters first");
141:
142: transverseMercator.asPlanar(q0, p);
143: p.x = SCALE_FACTOR * p.x + FALSE_EASTING;
144: p.y = SCALE_FACTOR * p.y + FALSE_NORTHING;
145: return p;
146: }
147:
148: }
|