-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdllmain_geoconvert.cpp
220 lines (181 loc) · 6.34 KB
/
dllmain_geoconvert.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// dllmain.cpp : Defines the entry point for the DLL application.
#ifdef WIN32
#include <windows.h>
#endif // WIN32
#include "geoconvert.h"
#include <math.h>
#include "mgrs.h"
#include "utm.h"
#ifdef WIN32
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif // WIN32
/*TEST(geoconvert, wgs_2_utm_2_wgs)
{
long zone;
char hemisphere;
double easting;
double northing;
double longitude[4] = { 0, 45, 90, 135 };
double latitude[2] = { -45, 45 };
double calculated_latitude;
double calculated_longitude;
double allowed_error = 0.00001;
for (int j = 0; j < 2; j++)
{
for (int i = 0; i < 4; i++)
{
EXPECT_EQ(gconv_wgs84_2_utm(&zone, &hemisphere, &easting, &northing, latitude[j], longitude[i]), GCONV_SUCCESS);
EXPECT_EQ(gconv_utm_2_wgs84(&calculated_latitude, &calculated_longitude, zone, hemisphere, easting, northing), GCONV_SUCCESS);
EXPECT_TRUE(allowed_error > abs((latitude[j] - calculated_latitude)));
EXPECT_TRUE(allowed_error > abs((longitude[i] - calculated_longitude)));
}
}
}
TEST(geoconvert, wgs_2_mgrs_2_wgs)
{
char mgrs[256];
double longitude[4] = { 0, 45, 90, 135 };
double latitude[2] = { -45, 45 };
double calculated_latitude;
double calculated_longitude;
double allowed_error = 0.00001;
for (int j = 0; j < 2; j++)
{
for (int i = 0; i < 4; i++)
{
EXPECT_EQ(gconv_wgs84_2_mgrs(mgrs, latitude[j], longitude[i]), GCONV_SUCCESS);
EXPECT_EQ(gconv_mgrs_2_wgs84(&calculated_latitude, &calculated_longitude, mgrs), GCONV_SUCCESS);
EXPECT_TRUE(allowed_error > abs((latitude[j] - calculated_latitude)));
EXPECT_TRUE(allowed_error > abs((longitude[i] - calculated_longitude)));
}
}
}
TEST(geoconvert, wgs_2_mgrs_2_wgs_for_specific_lat_lon_values)
{
char mgrs[256];
double longitude[3] = { 0, 90, -90 };
double latitude = 72;
double calculated_latitude;
double calculated_longitude;
double allowed_error = 0.00001;
for (int i = 0; i < 3; i++)
{
EXPECT_EQ(gconv_wgs84_2_mgrs(mgrs, latitude, longitude[i]), GCONV_SUCCESS);
EXPECT_EQ(gconv_mgrs_2_wgs84(&calculated_latitude, &calculated_longitude, mgrs), GCONV_SUCCESS);
EXPECT_TRUE(allowed_error > abs((latitude - calculated_latitude)));
EXPECT_TRUE(allowed_error > abs((longitude[i] - calculated_longitude)));
}
}
TEST(geoconvert, wgs_2_mgrs_2_wgs_for_long_180)
{
char mgrs[256];
double longitude = 180;
double latitude = 72;
double calculated_latitude;
double calculated_longitude;
double allowed_error = 0.00001;
EXPECT_EQ(gconv_wgs84_2_mgrs(mgrs, latitude, longitude), GCONV_SUCCESS);
EXPECT_EQ(gconv_mgrs_2_wgs84(&calculated_latitude, &calculated_longitude, mgrs), GCONV_SUCCESS);
EXPECT_TRUE(allowed_error > abs((latitude - abs(calculated_latitude))));
EXPECT_TRUE(allowed_error > abs((longitude - abs(calculated_longitude))));
}
TEST(geoconvert, wgs_2_utm_2_wgs_for_long_180)
{
long zone;
char hemisphere;
double easting;
double northing;
double longitude = 180;
double latitude[2] = { -45, 45 };
double calculated_latitude;
double calculated_longitude;
double allowed_error = 0.00001;
for (int j = 0; j < 2; j++)
{
EXPECT_EQ(gconv_wgs84_2_utm(&zone, &hemisphere, &easting, &northing, latitude[j], longitude), GCONV_SUCCESS);
EXPECT_EQ(gconv_utm_2_wgs84(&calculated_latitude, &calculated_longitude, zone, hemisphere, easting, northing), GCONV_SUCCESS);
EXPECT_TRUE(allowed_error > abs((latitude[j] - calculated_latitude)));
EXPECT_TRUE(allowed_error > abs((longitude - abs(calculated_longitude))));
}
}
TEST(geoconvert, usage_with_bad_values)
{
char mgrs[256];
char* bad_mgrs = "badval";
double longitude = 200;
double latitude = 200;
long zone;
char hemisphere;
double easting;
double northing;
double calculated_latitude;
double calculated_longitude;
EXPECT_EQ(gconv_wgs84_2_mgrs(mgrs, latitude, longitude), GCONV_FAILURE);
EXPECT_EQ(gconv_mgrs_2_wgs84(&calculated_latitude, &calculated_longitude, bad_mgrs), GCONV_FAILURE);
EXPECT_EQ(gconv_utm_2_wgs84(&calculated_latitude, &calculated_longitude, 2012, 'D', 0, 0), GCONV_FAILURE);
EXPECT_EQ(gconv_wgs84_2_utm(&zone, &hemisphere, &easting, &northing, latitude, longitude), GCONV_FAILURE);
}*/
extern "C"
{
const double PI = 3.14159265358979323846;
GCONV_CALL gconv_wgs84_2_mgrs(char* MGRS,
double Latitude,
double Longitude)
{
double lat = Latitude*PI/180.0;
double lng = Longitude*PI/180.0;
int status = Convert_Geodetic_To_MGRS(lat, lng, 5, MGRS);
return (status != MGRS_NO_ERROR) ? GCONV_FAILURE : GCONV_SUCCESS;
}
GCONV_CALL gconv_mgrs_2_wgs84(double* Latitude,
double* Longitude,
const char* MGRS)
{
double lat = 0;
double lng = 0;
int status = Convert_MGRS_To_Geodetic((char*)MGRS, &lat, &lng);
*Latitude = lat*180.0/PI;
*Longitude = lng*180.0/PI;
return (status != MGRS_NO_ERROR) ? GCONV_FAILURE : GCONV_SUCCESS;
}
GCONV_CALL gconv_wgs84_2_utm(long *Zone,
char *Hemisphere,
double *Easting,
double *Northing,
double Latitude,
double Longitude)
{
double lat = Latitude*PI/180.0;
double lng = Longitude*PI/180.0;
int status = Convert_Geodetic_To_UTM(lat, lng, Zone, Hemisphere, Easting, Northing);
return (status != UTM_NO_ERROR) ? GCONV_FAILURE : GCONV_SUCCESS;
}
GCONV_CALL gconv_utm_2_wgs84(double *Latitude,
double *Longitude,
long Zone,
char Hemisphere,
double Easting,
double Northing)
{
double lat = 0;
double lng = 0;
int status = Convert_UTM_To_Geodetic(Zone, Hemisphere, Easting, Northing, &lat, &lng);
*Latitude = lat*180.0/PI;
*Longitude = lng*180.0/PI;
return (status != UTM_NO_ERROR) ? GCONV_FAILURE : GCONV_SUCCESS;
}
}