LRAUV  revA
Datum_Test.h
Go to the documentation of this file.
1 /* \file
2  *
3  * Contains the test cases for the Datum class
4  *
5  * Copyright (c) 2007,2008,2009 MBARI
6  * MBARI Proprietary Information. All Rights Reserved
7  *
8  */
9 
10 #ifndef _DATUM_TEST_H_
11 #define _DATUM_TEST_H_
12 
13 #include "utils/Datum.h"
14 
15 #include <cxxtest/TestSuite.h>
16 
17 const double UTMFUDGE = 10.0;
18 const double LATLONFUDGE = 0.01;
19 
20 // Test data.
22 {
23  unsigned int zone;
25  double lat, lon;
26 };
27 
36 {
37  {9, 3637397.3, 504490.29, 32.8747, -128.952}, // This gave a UTM easting error at one time
38  {13, 7020000.00, 601000.00, 63.29460, -102.98545},
39  {45, 4041000.00, 310000.00, -53.74495, 84.11865},
40  {30, 1000000.00, 320000.00, 9.04290, -4.63762},
41  {1, 2006662.71, 536362.95, -72.036631, -175.94358},
42  {22, 3000000.00, 340000.00, 27.11319, -52.61415},
43  {43, 4000000.00, 350000.00, -54.12621, 72.704513},
44  {32, 5000000.00, 360000.00, 45.13959, 7.21936},
45  {51, 6000000.00, 370000.00, -36.136002, 121.55516},
46  {23, 7000000.00, 380000.00, 63.1093989, -47.378387},
47  {27, 8000000.00, 390000.00, -18.085908, -22.039540},
48  {18, 1000000.00, 400000.00, 9.0454332, -75.909879},
49  {52, 2000000.00, 410000.00, -72.08165, 126.37834},
50  {37, 3000000.00, 420000.00, 27.1201503, 38.19282790},
51  {28, 3000000.00, 430000.00, -63.1225521, -16.3878649},
52  {19, 4000000.00, 440000.00, 36.142861187, -69.66692297},
53  {16, 5002000.00, 450000.00, -45.1337036, -87.6358752},
54  {10, 6653097.435007, 611544.041980, 60, -121}, // This one is one the boundary between 10 and 11, which can cause the utm->latlon->utm conversion to fail
55  {9, 3988112.0, 770420.7, 36, -126.00001}, // This one is one the easting boundaries between 9 and 10, which can cause the utm->latlon->utm conversion to fail
56  {10, 3988112.0, 229587.58, 36, -125.9999}, // This one is one the easting boundaries between 9 and 10, which can cause the utm->latlon->utm conversion to fail
57  {16, 3319206.291, 403549.8474, 30, -88},
58  {27, 1879826.693, 393552.2529, 17, -22},
59  {43, 3320469.355, 692915.1064, 30, 77},
60  {51, 6653097.504, 388455.9545, 60, 121},
61  {55, 4429673.051, 670725.4996, 40, 149},
62  {53, 5792297.556, 324396.6244, -38, 133},
63  {36, 5127641.036, 419825.74, -44, 32},
64  {54, 1453013.284, 525110.2007, -77, 142},
65  {7, 2791172.394, 452844.8776, -65, -142},
66  {27, 8894421.383, 609600.7722, -10, -20},
67  {17, 3903379.219, 627928.1961, -55, -79},
68  {31, 0, 500000, 0, 3},
69  {31, 0, 166021.5497, 0, 0},
70  {0, 0, 0, 0, 0}
71 };
72 
73 
79 class Datum_Test : public CxxTest::TestSuite
80 {
81 public:
82 
83  void testLatLonToUtm( void )
84  {
85  unsigned int zone = 0;
86  double northings = 0.0, eastings = 0.0;
87  bool northernHemi = true;
88  char message[80];
89 
90  for( int i = 0; testData[i].zone != 0; i++ )
91  {
92  long error = Wgs84::LatLonToUtm( D2R( testData[i].lat ),
93  D2R( testData[i].lon ),
94  northings, eastings, zone, northernHemi );
95 
96  snprintf( message, 79, "Testing lat/long %.3lf,%.3lf", testData[i].lat, testData[i].lon );
97  TSM_ASSERT_EQUALS( message, error, 0 );
98  TSM_ASSERT_EQUALS( message, zone, testData[i].zone );
99  TSM_ASSERT_DELTA( message, northings, testData[i].northings, UTMFUDGE );
100  TSM_ASSERT_DELTA( message, eastings, testData[i].eastings, UTMFUDGE );
101  TSM_ASSERT_EQUALS( message, northernHemi, ( testData[i].lat >= 0 ) );
102 
103  double lat = 0.0, lon = 0.0;
104 
105  // Now test reverse calculation
106  error = Wgs84::UtmToLatLon( northings,
107  eastings,
108  zone,
109  northernHemi,
110  lat, lon );
111  lat = R2D( lat );
112  lon = R2D( lon );
113  TSM_ASSERT_EQUALS( message, error , 0 );
114  TSM_ASSERT_DELTA( message, lat, testData[i].lat, LATLONFUDGE );
115  TSM_ASSERT_DELTA( message, lon, testData[i].lon, LATLONFUDGE );
116  }
117 
118  }
119 
120 
121  void testUtmToLatLon( void )
122  {
123 
124  for( int i = 0; testData[i].zone != 0; i++ )
125  {
126  double lat = 0.0, lon = 0.0;
127  char message[80];
128  // I'm going to cheat a little since I don't have the N/S
129  // hemi info in the table .. just get the answer from the
130  // lat
131 
132  long error = Wgs84::UtmToLatLon( testData[i].northings,
133  testData[i].eastings,
134  testData[i].zone,
135  testData[i].lat >= 0,
136  lat, lon );
137  lat = R2D( lat );
138  lon = R2D( lon );
139  snprintf( message, 79, "Testing N/E %.3lf,%.3lf", testData[i].northings, testData[i].eastings );
140  TSM_ASSERT_EQUALS( message, error, 0 );
141  TSM_ASSERT_DELTA( message, lat, testData[i].lat, LATLONFUDGE );
142  TSM_ASSERT_DELTA( message, lon, testData[i].lon, LATLONFUDGE );
143 
144  // Now test the reverse calculation
145  double northings = 0.0, eastings = 0.0;
146  unsigned int zone = 0;
147  bool northernHemi = true;
148 
149  error = Wgs84::LatLonToUtm( D2R( lat ), D2R( lon ),
150  northings, eastings, zone, northernHemi );
151 
152  TSM_ASSERT_EQUALS( message, error, 0 );
153  TSM_ASSERT_EQUALS( message, zone, testData[i].zone );
154  TSM_ASSERT_DELTA( message, northings, testData[i].northings, UTMFUDGE );
155  TSM_ASSERT_DELTA( message, eastings, testData[i].eastings, UTMFUDGE );
156  TSM_ASSERT_EQUALS( message, northernHemi, ( testData[i].lat >= 0 ) );
157 
158  }
159 
160  }
161 
162 };
163 
164 
165 
166 #endif // _DATUM_TEST_H
Contains the CodedStr class declaration.
void testUtmToLatLon(void)
Definition: Datum_Test.h:121
#define R2D(x)
A macro for converting radians to degrees.
Definition: AuvMath.h:44
#define D2R(x)
A macro for converting degrees to radians.
Definition: AuvMath.h:40
const double LATLONFUDGE
Definition: Datum_Test.h:18
unsigned int zone
Definition: Datum_Test.h:23
void testLatLonToUtm(void)
Definition: Datum_Test.h:83
static long LatLonToUtm(const double lat, const double lon, double &northings, double &eastings, unsigned int &zone, bool &northernHemi)
Converts a lat and lon (in radians!) to northings/eastings/zone.
Definition: Datum.h:66
Definition: Datum_Test.h:21
double lat
Definition: Datum_Test.h:25
double lon
Definition: Datum_Test.h:25
DatumDataStruct testData[]
The original test data set was generated using the spreadsheet at: http://www.uwgb.edu/dutchs/UsefulData/UTMFormulas.HTM originally as a utm-to-latlon and latlon-to-utm set (should be easy to tell apart based on the round numbers).
Definition: Datum_Test.h:35
double eastings
Definition: Datum_Test.h:24
static long UtmToLatLon(const double northings, const double eastings, const unsigned int zone, const bool northernHemi, double &lat, double &lon)
Converts a UTM and zone to lat/lon (in radians!).
Definition: Datum.h:49
double northings
Definition: Datum_Test.h:24
Units tests for class Datum
Definition: Datum_Test.h:79
const double UTMFUDGE
Definition: Datum_Test.h:17