4
/***************************************************************************/
5
/* RSC IDENTIFIER: USNG
9
* This component converts between geodetic coordinates (latitude and
10
* longitude) and United States National Grid (USNG) coordinates.
14
* This component checks parameters for valid values. If an invalid value
15
* is found, the error code is combined with the current error code using
16
* the bitwise or. This combining allows multiple error codes to be
17
* returned. The possible error codes are:
19
* USNG_NO_ERROR : No errors occurred in function
20
* USNG_LAT_ERROR : Latitude outside of valid range
22
* USNG_LON_ERROR : Longitude outside of valid range
23
* (-180 to 360 degrees)
24
* USNG_STR_ERROR : An USNG string error: string too long,
25
* too short, or badly formed
26
* USNG_PRECISION_ERROR : The precision must be between 0 and 5
28
* USNG_A_ERROR : Semi-major axis less than or equal to zero
29
* USNG_INV_F_ERROR : Inverse flattening outside of valid range
31
* USNG_EASTING_ERROR : Easting outside of valid range
32
* (100,000 to 900,000 meters for UTM)
33
* (0 to 4,000,000 meters for UPS)
34
* USNG_NORTHING_ERROR : Northing outside of valid range
35
* (0 to 10,000,000 meters for UTM)
36
* (0 to 4,000,000 meters for UPS)
37
* USNG_ZONE_ERROR : Zone outside of valid range (1 to 60)
38
* USNG_HEMISPHERE_ERROR : Invalid hemisphere ('N' or 'S')
42
* USNG is intended for reuse by any application that does conversions
43
* between geodetic coordinates and USNG coordinates.
47
* Further information on USNG can be found in the Reuse Manual.
49
* USNG originated from : Federal Geographic Data Committee
51
* 12201 Sunrise Valley Drive
56
* None apply to this component.
63
* USNG was tested and certified in the following environments:
65
* 1. Solaris 2.5 with GCC version 2.8.1
66
* 2. Windows 95 with MS Visual C++ version 6
72
* 06-05-06 Original Code (cloned from MGRS)
77
/***************************************************************************/
82
#define USNG_NO_ERROR 0x0000
83
#define USNG_LAT_ERROR 0x0001
84
#define USNG_LON_ERROR 0x0002
85
#define USNG_STRING_ERROR 0x0004
86
#define USNG_PRECISION_ERROR 0x0008
87
#define USNG_A_ERROR 0x0010
88
#define USNG_INV_F_ERROR 0x0020
89
#define USNG_EASTING_ERROR 0x0040
90
#define USNG_NORTHING_ERROR 0x0080
91
#define USNG_ZONE_ERROR 0x0100
92
#define USNG_HEMISPHERE_ERROR 0x0200
93
#define USNG_LAT_WARNING 0x0400
96
/***************************************************************************/
101
/* ensure proper linkage to c++ programs */
107
long Set_USNG_Parameters(double a,
109
char *Ellipsoid_Code);
111
* The function Set_USNG_Parameters receives the ellipsoid parameters and sets
112
* the corresponding state variables. If any errors occur, the error code(s)
113
* are returned by the function, otherwise USNG_NO_ERROR is returned.
115
* a : Semi-major axis of ellipsoid in meters (input)
116
* f : Flattening of ellipsoid (input)
117
* Ellipsoid_Code : 2-letter code for ellipsoid (input)
121
void Get_USNG_Parameters(double *a,
123
char *Ellipsoid_Code);
125
* The function Get_USNG_Parameters returns the current ellipsoid
128
* a : Semi-major axis of ellipsoid, in meters (output)
129
* f : Flattening of ellipsoid (output)
130
* Ellipsoid_Code : 2-letter code for ellipsoid (output)
134
long Convert_Geodetic_To_USNG (double Latitude,
139
* The function Convert_Geodetic_To_USNG converts geodetic (latitude and
140
* longitude) coordinates to a USNG coordinate string, according to the
141
* current ellipsoid parameters. If any errors occur, the error code(s)
142
* are returned by the function, otherwise USNG_NO_ERROR is returned.
144
* Latitude : Latitude in radians (input)
145
* Longitude : Longitude in radians (input)
146
* Precision : Precision level of USNG string (input)
147
* USNG : USNG coordinate string (output)
152
long Convert_USNG_To_Geodetic (char *USNG,
156
* This function converts a USNG coordinate string to Geodetic (latitude
157
* and longitude in radians) coordinates. If any errors occur, the error
158
* code(s) are returned by the function, otherwise USNG_NO_ERROR is returned.
160
* USNG : USNG coordinate string (input)
161
* Latitude : Latitude in radians (output)
162
* Longitude : Longitude in radians (output)
167
long Convert_UTM_To_USNG (long Zone,
174
* The function Convert_UTM_To_USNG converts UTM (zone, easting, and
175
* northing) coordinates to a USNG coordinate string, according to the
176
* current ellipsoid parameters. If any errors occur, the error code(s)
177
* are returned by the function, otherwise USNG_NO_ERROR is returned.
179
* Zone : UTM zone (input)
180
* Hemisphere : North or South hemisphere (input)
181
* Easting : Easting (X) in meters (input)
182
* Northing : Northing (Y) in meters (input)
183
* Precision : Precision level of USNG string (input)
184
* USNG : USNG coordinate string (output)
188
long Convert_USNG_To_UTM (char *USNG,
194
* The function Convert_USNG_To_UTM converts a USNG coordinate string
195
* to UTM projection (zone, hemisphere, easting and northing) coordinates
196
* according to the current ellipsoid parameters. If any errors occur,
197
* the error code(s) are returned by the function, otherwise UTM_NO_ERROR
200
* USNG : USNG coordinate string (input)
201
* Zone : UTM zone (output)
202
* Hemisphere : North or South hemisphere (output)
203
* Easting : Easting (X) in meters (output)
204
* Northing : Northing (Y) in meters (output)
209
long Convert_UPS_To_USNG ( char Hemisphere,
216
* The function Convert_UPS_To_USNG converts UPS (hemisphere, easting,
217
* and northing) coordinates to a USNG coordinate string according to
218
* the current ellipsoid parameters. If any errors occur, the error
219
* code(s) are returned by the function, otherwise UPS_NO_ERROR is
222
* Hemisphere : Hemisphere either 'N' or 'S' (input)
223
* Easting : Easting/X in meters (input)
224
* Northing : Northing/Y in meters (input)
225
* Precision : Precision level of USNG string (input)
226
* USNG : USNG coordinate string (output)
230
long Convert_USNG_To_UPS ( char *USNG,
235
* The function Convert_USNG_To_UPS converts a USNG coordinate string
236
* to UPS (hemisphere, easting, and northing) coordinates, according
237
* to the current ellipsoid parameters. If any errors occur, the error
238
* code(s) are returned by the function, otherwide UPS_NO_ERROR is returned.
240
* USNG : USNG coordinate string (input)
241
* Hemisphere : Hemisphere either 'N' or 'S' (output)
242
* Easting : Easting/X in meters (output)
243
* Northing : Northing/Y in meters (output)