UNCLASSIFIED

GeographicTranslator
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
MGRS.h
Go to the documentation of this file.
1 // CLASSIFICATION: UNCLASSIFIED
2 
3 #ifndef MGRS_H
4 #define MGRS_H
5 
6 /***************************************************************************/
7 /* RSC IDENTIFIER: MGRS
8  *
9  * ABSTRACT
10  *
11  * This component converts between geodetic coordinates (latitude and
12  * longitude) and Military Grid Reference System (MGRS) coordinates.
13  *
14  * ERROR HANDLING
15  *
16  * This component checks parameters for valid values. If an invalid value
17  * is found, the error code is combined with the current error code using
18  * the bitwise or. This combining allows multiple error codes to be
19  * returned. The possible error codes are:
20  *
21  * MGRS_NO_ERROR : No errors occurred in function
22  * MGRS_LAT_ERROR : Latitude outside of valid range
23  * (-90 to 90 degrees)
24  * MGRS_LON_ERROR : Longitude outside of valid range
25  * (-180 to 360 degrees)
26  * MGRS_STR_ERROR : An MGRS string error: string too long,
27  * too short, or badly formed
28  * MGRS_PRECISION_ERROR : The precision must be between 0 and 5
29  * inclusive.
30  * MGRS_A_ERROR : Semi-major axis less than or equal to zero
31  * MGRS_INV_F_ERROR : Inverse flattening outside of valid range
32  * (250 to 350)
33  * MGRS_EASTING_ERROR : Easting outside of valid range
34  * (100,000 to 900,000 meters for UTM)
35  * (0 to 4,000,000 meters for UPS)
36  * MGRS_NORTHING_ERROR : Northing outside of valid range
37  * (0 to 10,000,000 meters for UTM)
38  * (0 to 4,000,000 meters for UPS)
39  * MGRS_ZONE_ERROR : Zone outside of valid range (1 to 60)
40  * MGRS_HEMISPHERE_ERROR : Invalid hemisphere ('N' or 'S')
41  *
42  * REUSE NOTES
43  *
44  * MGRS is intended for reuse by any application that does conversions
45  * between geodetic coordinates and MGRS coordinates.
46  *
47  * REFERENCES
48  *
49  * Further information on MGRS can be found in the Reuse Manual.
50  *
51  * MGRS originated from : U.S. Army Topographic Engineering Center
52  * Geospatial Information Division
53  * 7701 Telegraph Road
54  * Alexandria, VA 22310-3864
55  *
56  * LICENSES
57  *
58  * None apply to this component.
59  *
60  * RESTRICTIONS
61  *
62  *
63  * ENVIRONMENT
64  *
65  * MGRS was tested and certified in the following environments:
66  *
67  * 1. Solaris 2.5 with GCC version 2.8.1
68  * 2. Windows 95 with MS Visual C++ version 6
69  *
70  * MODIFICATIONS
71  *
72  * Date Description
73  * ---- -----------
74  * 2-27-07 Original Code
75  */
76 
77 
78 #include "CoordinateSystem.h"
79 
80 
81 namespace MSP
82 {
83  namespace CCS
84  {
85  class UPS;
86  class UTM;
87  class EllipsoidParameters;
88  class MGRSorUSNGCoordinates;
89  class GeodeticCoordinates;
90  class UPSCoordinates;
91  class UTMCoordinates;
92 
93  #define MGRS_LETTERS 3
94 
95  /**********************************************************************/
96  /*
97  * DEFINES
98  */
99 
101  {
102  public:
103 
104  /*
105  * The constructor receives the ellipsoid parameters and sets
106  * the corresponding state variables. If any errors occur,
107  * an exception is thrown with a description of the error.
108  *
109  * ellipsoidSemiMajorAxis : Semi-major axis of ellipsoid (m) (input)
110  * ellipsoidFlattening : Flattening of ellipsoid (input)
111  * ellipsoid_Code : 2-letter code for ellipsoid (input)
112  */
113 
114  MGRS(
115  double ellipsoidSemiMajorAxis,
116  double ellipsoidFlattening,
117  char* ellipsoidCode );
118 
119 
120  MGRS( const MGRS &m );
121 
122 
123  ~MGRS( void );
124 
125 
126  MGRS& operator=( const MGRS &m );
127 
128 
129  /*
130  * The function getParameters returns the current ellipsoid
131  * parameters.
132  *
133  * ellipsoidSemiMajorAxis : Semi-major axis of ellipsoid, (m) (output)
134  * ellipsoidFlattening : Flattening of ellipsoid (output)
135  * ellipsoidCode : 2-letter code for ellipsoid (output)
136  */
137 
138  EllipsoidParameters* getParameters() const;
139 
140 
141  /*
142  * The function convertFromGeodetic converts Geodetic (latitude and
143  * longitude) coordinates to an MGRS coordinate string, according to the
144  * current ellipsoid parameters. If any errors occur,
145  * an exception is thrown with a description of the error.
146  *
147  * latitude : Latitude in radians (input)
148  * longitude : Longitude in radians (input)
149  * precision : Precision level of MGRS string (input)
150  * MGRSString : MGRS coordinate string (output)
151  *
152  */
153 
154  MSP::CCS::MGRSorUSNGCoordinates* convertFromGeodetic(
155  MSP::CCS::GeodeticCoordinates* geodeticCoordinates,
156  long precision );
157 
158  /*
159  * The function convertToGeodetic converts an MGRS coordinate string
160  * to Geodetic (latitude and longitude) coordinates
161  * according to the current ellipsoid parameters. If any errors occur,
162  * an exception is thrown with a description of the error.
163  *
164  * MGRS : MGRS coordinate string (input)
165  * latitude : Latitude in radians (output)
166  * longitude : Longitude in radians (output)
167  *
168  */
169 
170  MSP::CCS::GeodeticCoordinates* convertToGeodetic(
171  MSP::CCS::MGRSorUSNGCoordinates* mgrsCoordinates );
172 
173 
174  /*
175  * The function convertFromUTM converts UTM (zone, easting, and
176  * northing) coordinates to an MGRS coordinate string, according to the
177  * current ellipsoid parameters. If any errors occur,
178  * an exception is thrown with a description of the error.
179  *
180  * zone : UTM zone (input)
181  * hemisphere : North or South hemisphere (input)
182  * easting : Easting (X) in meters (input)
183  * northing : Northing (Y) in meters (input)
184  * precision : Precision level of MGRS string (input)
185  * MGRSString : MGRS coordinate string (output)
186  */
187 
188  MSP::CCS::MGRSorUSNGCoordinates* convertFromUTM(
189  UTMCoordinates* utmCoordinates, long precision );
190 
191 
192  /*
193  * The function convertToUTM converts an MGRS coordinate string
194  * to UTM projection (zone, hemisphere, easting and northing) coordinates
195  * according to the current ellipsoid parameters. If any errors occur,
196  * an exception is thrown with a description of the error.
197  *
198  * MGRSString : MGRS coordinate string (input)
199  * zone : UTM zone (output)
200  * hemisphere : North or South hemisphere (output)
201  * easting : Easting (X) in meters (output)
202  * northing : Northing (Y) in meters (output)
203  */
204 
205  MSP::CCS::UTMCoordinates* convertToUTM(
206  MSP::CCS::MGRSorUSNGCoordinates* mgrsorUSNGCoordinates );
207 
208  /*
209  * The function convertFromUPS converts UPS (hemisphere, easting,
210  * and northing) coordinates to an MGRS coordinate string according to
211  * the current ellipsoid parameters. If any errors occur,
212  * an exception is thrown with a description of the error.
213  *
214  * hemisphere : Hemisphere either 'N' or 'S' (input)
215  * easting : Easting/X in meters (input)
216  * northing : Northing/Y in meters (input)
217  * precision : Precision level of MGRS string (input)
218  * MGRSString : MGRS coordinate string (output)
219  */
220 
221  MSP::CCS::MGRSorUSNGCoordinates* convertFromUPS(
222  MSP::CCS::UPSCoordinates* upsCoordinates, long precision );
223 
224 
225  /*
226  * The function convertToUPS converts an MGRS coordinate string
227  * to UPS (hemisphere, easting, and northing) coordinates, according
228  * to the current ellipsoid parameters. If any errors occur,
229  * an exception is thrown with a description of the error.
230  *
231  * MGRSString : MGRS coordinate string (input)
232  * hemisphere : Hemisphere either 'N' or 'S' (output)
233  * easting : Easting/X in meters (output)
234  * northing : Northing/Y in meters (output)
235  */
236 
237  MSP::CCS::UPSCoordinates* convertToUPS(
238  MSP::CCS::MGRSorUSNGCoordinates* mgrsorUSNGCoordinates );
239 
240  private:
241 
242  UPS* ups;
243  UTM* utm;
244 
245  char MGRSEllipsoidCode[3];
246 
247 
248  /*
249  * The function fromUTM calculates an MGRS coordinate string
250  * based on the zone, latitude, easting and northing.
251  *
252  * zone : Zone number (input)
253  * hemisphere : Hemisphere (input)
254  * longitude : Longitude in radians (input)
255  * latitude : Latitude in radians (input)
256  * easting : Easting (input)
257  * northing : Northing (input)
258  * precision : Precision (input)
259  * MGRSString : MGRS coordinate string (output)
260  */
261 
263  MSP::CCS::UTMCoordinates* utmCoordinates,
264  double longitude,
265  double latitude,
266  long precision );
267 
268  /*
269  * The function toUTM converts an MGRS coordinate string
270  * to UTM projection (zone, hemisphere, easting and northing) coordinates
271  * according to the current ellipsoid parameters. If any errors occur,
272  * an exception is thrown with a description of the error.
273  *
274  * MGRSString : MGRS coordinate string (input)
275  * zone : UTM zone (output)
276  * hemisphere : North or South hemisphere (output)
277  * easting : Easting (X) in meters (output)
278  * northing : Northing (Y) in meters (output)
279  */
280 
282  long zone,
283  long letters[MGRS_LETTERS],
284  double easting,
285  double northing,
286  long in_precision );
287 
288 
289  /*
290  * The function fromUPS converts UPS (hemisphere, easting,
291  * and northing) coordinates to an MGRS coordinate string according to
292  * the current ellipsoid parameters.
293  *
294  * hemisphere : Hemisphere either 'N' or 'S' (input)
295  * easting : Easting/X in meters (input)
296  * northing : Northing/Y in meters (input)
297  * precision : Precision level of MGRS string (input)
298  * MGRSString : MGRS coordinate string (output)
299  */
300 
302  MSP::CCS::UPSCoordinates* upsCoordinates,
303  long precision );
304 
305  /*
306  * The function toUPS converts an MGRS coordinate string
307  * to UPS (hemisphere, easting, and northing) coordinates, according
308  * to the current ellipsoid parameters. If any errors occur, an
309  * exception is thrown with a description of the error.
310  *
311  * MGRSString : MGRS coordinate string (input)
312  * hemisphere : Hemisphere either 'N' or 'S' (output)
313  * easting : Easting/X in meters (output)
314  * northing : Northing/Y in meters (output)
315  */
316 
318  long letters[MGRS_LETTERS],
319  double easting, double northing );
320 
321  /*
322  * The function getGridValues sets the letter range used for
323  * the 2nd letter in the MGRS coordinate string, based on the set
324  * number of the utm zone. It also sets the pattern offset using a
325  * value of A for the second letter of the grid square, based on
326  * the grid pattern and set number of the utm zone.
327  *
328  * zone : Zone number (input)
329  * ltr2_low_value : 2nd letter low number (output)
330  * ltr2_high_value : 2nd letter high number (output)
331  * pattern_offset : Pattern offset (output)
332  */
333 
334  void getGridValues(
335  long zone,
336  long* ltr2_low_value,
337  long* ltr2_high_value,
338  double* pattern_offset );
339 
340 
341  /*
342  * The function getLatitudeBandMinNorthing receives a latitude band
343  * letter and uses the Latitude_Band_Table to determine the
344  * minimum northing and northing offset for that latitude band letter.
345  *
346  * letter : Latitude band letter (input)
347  * min_northing : Minimum northing for that letter (output)
348  * northing_offset : Latitude band northing offset (output)
349  */
350 
351  void getLatitudeBandMinNorthing(
352  long letter, double* min_northing, double* northing_offset );
353 
354 
355  /*
356  * The function inLatitudeRange receives a latitude band letter
357  * and uses the Latitude_Band_Table to determine if the latitude
358  * falls within the band boundaries for that latitude band letter.
359  *
360  * letter : Latitude band letter (input)
361  * latitude : Latitude to test (input)
362  * border : Border added to band in radians (input)
363  */
364 
365  bool inLatitudeRange( long letter, double latitude, double border );
366 
367 
368  /*
369  * The function getLatitudeLetter receives a latitude value
370  * and uses the Latitude_Band_Table to determine the latitude band
371  * letter for that latitude.
372  *
373  * latitude : Latitude (input)
374  * letter : Latitude band letter (output)
375  */
376 
377  void getLatitudeLetter( double latitude, int* letter );
378  };
379  }
380 }
381 
382 #endif
383 
384 
385 // CLASSIFICATION: UNCLASSIFIED