testUTMPoint.cc
Go to the documentation of this file.
1 
11 #include <utl/UTMPoint.h>
12 #include <utl/Point.h>
13 #include <utl/ReferenceEllipsoid.h>
14 
15 #include <tst/Verify.h>
16 #include <utl/Triple.h>
17 
18 #include <cppunit/extensions/HelperMacros.h>
19 
20 #include <iostream>
21 
22 using namespace utl;
23 using namespace tst;
24 
25 #define TEST_CLOSETO3(n1_, n2_, e1_, e2_, h1_, h2_) \
26  CPPUNIT_ASSERT(Verify<CloseTo>(n1_, n2_)); \
27  CPPUNIT_ASSERT(Verify<CloseTo>(e1_, e2_)); \
28  CPPUNIT_ASSERT(Verify<CloseTo>(h1_, h2_))
29 
30 
34 class testUTMPoint : public CppUnit::TestFixture {
35 
36  CPPUNIT_TEST_SUITE(testUTMPoint);
37  CPPUNIT_TEST(testConstructors);
38  CPPUNIT_TEST(testAssignement);
39  CPPUNIT_TEST(testLatLongConversions);
40  CPPUNIT_TEST(testUTMConversions);
41  CPPUNIT_TEST_SUITE_END();
42 
43 private:
44  void
45  oneLatLongConversion(const double la, const double lo, const double n, const double e,
46  const double h, const int z, const char b)
47  {
48  const UTMPoint p(la, lo, h, ReferenceEllipsoid::eWGS84);
49  CPPUNIT_ASSERT(Verify<CloseTo>(
50  p.GetGeodeticCoordinates(), Triple(la, lo, h)));
51  CPPUNIT_ASSERT(p.GetZone() == z);
52  CPPUNIT_ASSERT(p.GetBand() == b);
53  /*TEST_CLOSETO3(p.GetNorthing(), n,
54  p.GetEasting(), e,
55  p.GetHeight(), h);*/
56  CPPUNIT_ASSERT(Verify<CloseTo>(
57  p.GetCoordinates3(), Triple(n, e, h)));
58 
59  const UTMPoint q(n, e, h, z, b, ReferenceEllipsoid::eWGS84);
60  CPPUNIT_ASSERT(Verify<CloseTo>(
61  q.GetGeodeticCoordinates(), Triple(la, lo, h)));
62  CPPUNIT_ASSERT(q.GetZone() == z);
63  CPPUNIT_ASSERT(q.GetBand() == b);
64  /*TEST_CLOSETO3(q.GetNorthing(), n,
65  q.GetEasting(), e,
66  q.GetHeight(), h);*/
67  CPPUNIT_ASSERT(Verify<CloseTo>(
68  q.GetCoordinates3(), Triple(n, e, h)));
69  }
70 
71  void
72  oneUTMConversion(const double /*la*/, const double /*lo*/, const double n, const double e,
73  const double h, const int z, const char b)
74  {
75  const UTMPoint up(n, e, h, z, b, ReferenceEllipsoid::eWGS84);
76  const Point cp(up.GetPoint());
78 
79  CPPUNIT_ASSERT(Verify<CloseTo>(
80  up.GetCoordinates3(), uq.GetCoordinates3()));
81  CPPUNIT_ASSERT(up.GetZone() == uq.GetZone());
82  CPPUNIT_ASSERT(up.GetBand() == uq.GetBand());
83  }
84 
85 public:
86  void setUp() { }
87 
88  void tearDown() { }
89 
90  void dummy(UTMPoint /*p*/) { };
91 
92  void
94  {
96  const UTMPoint p1(10000, 500000, 0, 10, 'I', e);
97  CPPUNIT_ASSERT(p1.GetNorthing() == 10000);
98  CPPUNIT_ASSERT(p1.GetEasting() == 500000);
99  CPPUNIT_ASSERT(p1.GetHeight() == 0);
100  CPPUNIT_ASSERT(p1.GetZone() == 10);
101  CPPUNIT_ASSERT(p1.GetBand() == 'I');
102  CPPUNIT_ASSERT(p1.GetEllipsoid() == e);
103  CPPUNIT_ASSERT(p1.GetCoordinates() ==
104  boost::make_tuple(10000, 500000, 0, 10., 'I'));
105  CPPUNIT_ASSERT(p1.GetCoordinates4() ==
106  boost::make_tuple(10000, 500000, 0, 10));
107  CPPUNIT_ASSERT(p1.GetCoordinates3() ==
108  Triple(10000, 500000, 0));
109 
110  const UTMPoint p2(9345711., 821935., 1432., 7, 'L', ReferenceEllipsoid::eWGS84);
111  CPPUNIT_ASSERT(p2.GetCoordinates() ==
112  boost::make_tuple(9345711., 821935., 1432., 7, 'L'));
113  CPPUNIT_ASSERT(p2.GetEllipsoid() == e);
114 
115  const UTMPoint p3(p2, e);
116  CPPUNIT_ASSERT(p2 == p3);
117  }
118 
119  void
121  {
123  const UTMPoint p0(10000, 500000, 0, 10, 'I', e);
124  UTMPoint p1(0, 0, 100, 11, 'J', e);
125 
126  CPPUNIT_ASSERT(p1 != p0);
127 
128  p1 = p0;
129  CPPUNIT_ASSERT(p1 == p0);
130  CPPUNIT_ASSERT(p1.GetNorthing() == 10000);
131  CPPUNIT_ASSERT(p1.GetEasting() == 500000);
132  CPPUNIT_ASSERT(p1.GetHeight() == 0);
133  CPPUNIT_ASSERT(p1.GetZone() == 10);
134  CPPUNIT_ASSERT(p1.GetBand() == 'I');
135  CPPUNIT_ASSERT(p1.GetEllipsoid() == e);
136  CPPUNIT_ASSERT(p1.GetCoordinates() ==
137  boost::make_tuple(10000, 500000, 0, 10., 'I'));
138  CPPUNIT_ASSERT(p1.GetCoordinates4() ==
139  boost::make_tuple(10000, 500000, 0, 10));
140  CPPUNIT_ASSERT(p1.GetCoordinates3() ==
141  Triple(10000, 500000, 0));
142 
143  }
144 
145  void
147  {
148  for (LatLongNorthEast* p = llneData;
149  p < llneData + sizeof(llneData)/sizeof(LatLongNorthEast);
150  ++p) {
151  oneLatLongConversion(p->fLat, p->fLong, p->fNorth, p->fEast,
152  testHeight, testZone, testBand);
153  }
154  }
155 
156  void
158  {
159  // Note: in all these tests, be aware that rounding errors near
160  // zone or band boundaries can place the point you convert from
161  // lat/long to UTM into the neighbouring zone or band. These
162  // errors cancel when you convert back. The resulting UTM
163  // representation is valid, since the UTM zones have some
164  // overlap.
165  const CoordinateSystemPtr cs = CoordinateSystem::GetRootCoordinateSystem();
167 
168  const UTMPoint up1(0*deg, 0*deg, 0*m, ReferenceEllipsoid::eWGS84);
169  CPPUNIT_ASSERT(up1.GetZone() == 31);
170  CPPUNIT_ASSERT(up1.GetBand() == 'N');
171 
172  /*TEST_CLOSETO3(up1.GetNorthing(), 0*m,
173  up1.GetEasting(), 166021.44*m,
174  up1.GetHeight(), 0*m);*/
175  CPPUNIT_ASSERT(Verify<CloseTo>(
176  up1.GetCoordinates3(), Triple(0*m, 166021.44*m, 0*m)));
177  CPPUNIT_ASSERT(Verify<CloseTo>(
178  up1.GetGeodeticCoordinates(), Triple(0.*deg, 0.*deg, 0.*m)));
179  const Point p1(up1.GetPoint());
180  CPPUNIT_ASSERT(Verify<CloseTo>(
181  p1.GetCoordinates(cs), Triple(e.GetEquatorialRadius(), 0, 0)));
182 
183  // made longitude slightly larger than 90 deg to avoid rounding problems
184  const UTMPoint up2(0*deg, 90.0000000001*deg, 0*m, ReferenceEllipsoid::eWGS84);
185  CPPUNIT_ASSERT(up2.GetZone() == 46);
186  CPPUNIT_ASSERT(up2.GetBand() == 'N');
187  CPPUNIT_ASSERT(Verify<CloseTo>(
188  up2.GetCoordinates3(), Triple(0*m, 166021.44*m, 0*m)));
189  CPPUNIT_ASSERT(Verify<CloseTo>(
190  up2.GetGeodeticCoordinates(), Triple(0.*deg, 90.*deg, 0.*m)));
191  const Point p2(up2.GetPoint());
192  CPPUNIT_ASSERT(Verify<CloseTo>(
193  p2.GetCoordinates(cs), Triple(0., e.GetEquatorialRadius(), 0.)));
194 
195  const UTMPoint up3(1*deg, 90*deg, 0*m, ReferenceEllipsoid::eWGS84);
196  CPPUNIT_ASSERT(up3.GetZone() == 45);
197  CPPUNIT_ASSERT(up3.GetBand() == 'N');
198  CPPUNIT_ASSERT(Verify<CloseTo>(
199  up3.GetGeodeticCoordinates(), Triple(1.*deg, 90.*deg, 0.*m)));
200 
201  const UTMPoint up4(-1*deg, 90*deg, 0*m, ReferenceEllipsoid::eWGS84);
202  CPPUNIT_ASSERT(up4.GetZone() == 45);
203  CPPUNIT_ASSERT(up4.GetBand() == 'M');
204  CPPUNIT_ASSERT(Verify<CloseTo>(
205  up4.GetGeodeticCoordinates(), Triple(-1.*deg, 90.*deg, 0.*m)));
206 
207  const UTMPoint up5(0*deg, 91*deg, 0*m, ReferenceEllipsoid::eWGS84);
208  CPPUNIT_ASSERT(up5.GetZone() == 46);
209  CPPUNIT_ASSERT(up5.GetBand() == 'N');
210  CPPUNIT_ASSERT(Verify<CloseTo>(
211  up5.GetGeodeticCoordinates(), Triple(0.*deg, 91.*deg, 0.*m)));
212 
213  for (LatLongNorthEast* p = llneData;
214  p < llneData + sizeof(llneData)/sizeof(LatLongNorthEast);
215  ++p) {
216  oneUTMConversion(p->fLat, p->fLong, p->fNorth, p->fEast,
217  testHeight, testZone, testBand);
218  }
219  }
220 
221 };
222 
223 
225 
226 
227 // Configure (x)emacs for this file ...
228 // Local Variables:
229 // mode: c++
230 // compile-command: "make -C .. -k testGeometry && ../testGeometry "
231 // End:
Point object.
Definition: Point.h:32
void testLatLongConversions()
void testUTMConversions()
boost::tuple< double, double, double, int, char > GetCoordinates() const
Get norting, easting, height, zone, and band.
Definition: UTMPoint.h:232
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
void dummy(UTMPoint)
Definition: testUTMPoint.cc:90
int GetZone() const
Get the zone.
Definition: UTMPoint.h:215
char GetBand() const
Get the band.
Definition: UTMPoint.h:218
void oneUTMConversion(const double, const double, const double n, const double e, const double h, const int z, const char b)
Definition: testUTMPoint.cc:72
static const ReferenceEllipsoid & Get(const EllipsoidID theID)
Get known ellipsoid by registered ID.
double GetNorthing() const
Get the northing.
Definition: UTMPoint.h:206
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
constexpr double deg
Definition: AugerUnits.h:140
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
void tearDown()
Definition: testUTMPoint.cc:88
boost::tuple< double, double, double > Triple
Coordinate triple for easy getting or setting of coordinates.
Definition: Triple.h:15
Reference ellipsoids for UTM transformations.
void testAssignement()
void testConstructors()
Definition: testUTMPoint.cc:93
double GetHeight() const
Get the height.
Definition: UTMPoint.h:212
double GetEquatorialRadius() const
Get equatorial radius ( )
double GetEasting() const
Get the easting.
Definition: UTMPoint.h:209
boost::tuple< double, double, double, int > GetCoordinates4() const
Get norting, easting, height, and zone.
Definition: UTMPoint.h:228
boost::tuple< double, double, double > GetCoordinates3() const
Get norting, easting, and height.
Definition: UTMPoint.h:224
const ReferenceEllipsoid & GetEllipsoid() const
Get the reference ellipsoid.
Definition: UTMPoint.h:221
Point GetPoint(const CoordinateSystemPtr &theCS=CoordinateSystemPtr()) const
Get a cartesian point from an UTMPoint.
Definition: UTMPoint.cc:45
void oneLatLongConversion(const double la, const double lo, const double n, const double e, const double h, const int z, const char b)
Definition: testUTMPoint.cc:45
constexpr double m
Definition: AugerUnits.h:121
boost::tuple< double, double, double > GetGeodeticCoordinates() const
Get geodetic latitude, longitude, height.
Definition: UTMPoint.cc:67

, generated on Tue Sep 26 2023.