UNCLASSIFIED

GeographicTranslator
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
WebMercator.cpp
Go to the documentation of this file.
1 // CLASSIFICATION: UNCLASSIFIED
2 /***************************************************************************/
3 /* RSC IDENTIFIER: Web Mercator
4  *
5  * ABSTRACT
6  *
7  * This component provides conversions between Geodetic coordinates
8  * (latitude and longitude) and Web Mercator coordinates
9  * (easting and northing).
10  *
11  * REFERENCES
12  *
13  * Further information on Web Mercator can be found in the NGA document
14  * "Implementation Practice Web Mercator Map Projection", 2014-02-18.
15  *
16  * LICENSES
17  *
18  * None apply to this component.
19  *
20  * MODIFICATIONS
21  *
22  * Date Description
23  * ---- -----------
24  * 06-14-14 Original Code
25  *
26  */
27 
28 #include <string.h>
29 #include <math.h>
30 #include "WebMercator.h"
31 #include "EllipsoidParameters.h"
33 #include "GeodeticCoordinates.h"
35 #include "ErrorMessages.h"
36 
37 /*
38  * string.h - Standard C string handling library
39  * math.h - Standard C math library
40  * NZMG.h - Is for prototype error checking
41  * MapProjectionCoordinates.h - defines map projection coordinates
42  * GeodeticCoordinates.h - defines geodetic coordinates
43  * CoordinateConversionException.h - Exception handler
44  * ErrorMessages.h - Contains exception messages
45  */
46 
47 
48 using namespace MSP::CCS;
49 
50 
51 // DEFINES
52 const double PI = 3.14159265358979323e0;
53 
54 
55 WebMercator::WebMercator( char* ellipsoidCode ) :
56  CoordinateSystem( 6378137.0, 0.0 )
57 {
58  /*
59  * The constructor receives the ellipsoid code which must be "WE"
60  *
61  * ellipsoidCode : 2-letter code for ellipsoid (input)
62  */
63 
64  if (strcmp(ellipsoidCode, "WE") != 0)
65  { /* Ellipsoid must be WGS84 */
67  }
68 }
69 
70 
72 {
73 /*
74  * The function getParameters returns the current ellipsoid code.
75  *
76  * ellipsoidCode : 2-letter code for ellipsoid (output)
77  */
78 
79  return new EllipsoidParameters(
80  semiMajorAxis, flattening, "WE" ); // Always WGS84 radius
81 }
82 
84  MSP::CCS::GeodeticCoordinates* geodeticCoordinates )
85 {
86  double longitude = geodeticCoordinates->longitude();
87  double latitude = geodeticCoordinates->latitude();
88 
89  double easting = longitude * semiMajorAxis;
90  double northing = semiMajorAxis * log( tan( PI/4.0 + latitude / 2.0 ) );
91 
92  // Always throw an error because NGA does not want to allow
93  // conversions to Web Mecator
95 
96  return new MapProjectionCoordinates(
97  CoordinateType::webMercator, easting, northing );
98 }
99 
101  MSP::CCS::MapProjectionCoordinates* mapProjectionCoordinates )
102 {
103  double easting = mapProjectionCoordinates->easting();
104  double northing = mapProjectionCoordinates->northing();
105 
106  double longitude = easting / semiMajorAxis;
107  double latitude = 2.0 * atan( exp( northing / semiMajorAxis ) ) - PI/2.0;
108 
109  return new GeodeticCoordinates(
110  CoordinateType::geodetic, longitude, latitude );
111 }
112 
113 // CLASSIFICATION: UNCLASSIFIED