1 /*
2 * Trip Tracker, a real-time position tracking system for the Internet.
3 * Copyright (C) 2006 Team Trip Tracker
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 package triptracker.testing;
21
22 import triptracker.core.Coordinate;
23 import triptracker.core.UTMPoint;
24
25 public class UTMtest {
26
27 public static void main(String[] args) {
28 int j, k; // lat: dd, mm, ss
29 int j1, k1; // lon: dd, mm, ss
30 double i1, l1;
31 int i;
32
33 j = 58; // lat dd
34 k = 58; // lat mm
35 i1 = 3.767; // lat ss
36 Double f4 = j + (double) k / 60 + i1 / 3600; // lat
37
38
39 j1 = 5; // lon ddd
40 k1 = 36; // lon mm
41 l1 = 6.661; // lon ss
42 Double f5 = j1 + (double) k1 / 60 + l1 / 3600; // lon
43
44 i = 22; // WGS84
45
46 // Coordinate latlon = new Coordinate(5858.3767, 536.6659);
47 Coordinate latlon = new Coordinate(58.97713055555554, 5.61849722222222);
48 UTMPoint utm = Coordinate.llToUTM(i, latlon.getY(), latlon.getX());
49 //UTMPoint utmpoint1 = UTMUtils.LLtoUTM(i, f4, f5);
50
51 Coordinate ll = Coordinate.utmToLl(i, utm.getNorthing(),
52 utm.getEasting(), utm.getZoneNumber(), utm.getZoneLetter());
53
54 System.out.println("* Start value: " + latlon.toString());
55 System.out.println("* Converted to UTM: N "+ utm.getNorthing()
56 + ", E " + utm.getEasting());
57 // System.out.println((new StringBuilder()).append("Northing : ")
58 // .append(String.valueOf(utmpoint1.northing))
59 // .append(" Easting : ")
60 // .append(String.valueOf(utmpoint1.easting))
61 // .append(" Zone: ")
62 // .append(String.valueOf(utmpoint1.zone_number))
63 // .append(String.valueOf(utmpoint1.zone_letter)).toString());
64 System.out.println("* Back to start: " + ll.toString());
65
66 // System.out.println((new StringBuilder()).append("Lat: ")
67 // .append(breakUp(latlonpoint.getLatitude())).append(" Lon: ")
68 // .append(breakUp(latlonpoint.lon)).toString());
69 // System.out.println((new StringBuilder()).append("Decimal Lat: ")
70 // .append(String.valueOf(latlonpoint.lat)).append(" Lon: ")
71 // .append(String.valueOf(latlonpoint.lon)).toString());
72 }
73
74 private static String breakUp(double f) {
75 double f1 = 0.00027;
76 double f2 = 0.01666666;
77 boolean flag = false;
78
79 if (f < 0) {
80 flag = true;
81 f = -f;
82 }
83
84 if (f < f1) {
85 return "0 deg";
86 }
87
88 StringBuffer sb = new StringBuffer(40);
89 sb.setLength(0);
90 if (flag) {
91 sb.append('-');
92 }
93
94 int i = (int)f;
95
96 if (i == 1) {
97 sb.append("1 deg");
98 } else {
99 sb.append(i).append(" deg");
100 }
101
102 double f3 = f - i;
103
104 if (f3 >= f2) {
105 int j = (int)(f3 * 60);
106 if (j == 1) {
107 sb.append(" 1 min");
108 } else {
109 sb.append(" ").append(j).append(" min");
110 }
111 f3 -= j * f2;
112 }
113
114 if (f3 >= f1) {
115 int k = (int)(f3 * 3600);
116 if (k == 1) {
117 sb.append(" 1 sec");
118 } else {
119 sb.append(" ").append(k).append(" sec");
120 }
121 f3 -= k * f1;
122 }
123 return sb.toString();
124 }
125 }