-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkoordi.cpp
executable file
·1153 lines (852 loc) · 37.9 KB
/
koordi.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
koordi.cpp - description
-------------------
begin : Mon Apr 10 2000
copyright : (C) 2004 by B. Friedrichs
email : geo@metronix.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* C++ (z. B. fuer Conv)
Routinen zur Koordinatentransformation
nach einem Fortran Program von K. Ivory
getestet:
Laenge Breite Meridian
10 42' 59.3215'' 48 26' 45.4355'' 12
rechts: 4.405057628849e+06 hoch: 5.368263247964e+06
Ergebinis 25.6.97
Laenge Breite
10 31' 55.9'' 52 15' 39.5''
Soll 4399796.57 5792799.64 rechts hoch
Ist 4399796.266583 5792800.787294
*/
#include "koordi.h"
// latitude, longitude in rad !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/***************************************************************************
* *
* first provide a function for clearing the class *
* *
* and a function for getting the lats and longs *
* *
* *
***************************************************************************/
void coordinates::set_z() {
latitude = longitude = rechts = hoch = lat = lon = 0.;
northing = easting = 0.;
this->gr_lo = this->mi_lo = this->gr_la = this->mi_la = 0;
this->se_lo = this->se_la = 0.;
elevation = 0.;
// undefined
gk_meridian = INT_MAX;
this->utm_meridian = INT_MAX;
ReferenceEllipsoid = INT_MAX;
this->LatH = "x";
this->LonH = "x";
// latmsec = lonmsec = 0;
}
/***************************************************************************
* *
* constructor with latitudes and longitudes *
* and meridians and ellipsoid *
* *
* *
* *
***************************************************************************/
coordinates::coordinates() {
set_z();
// as default start up we take the WGS-84
ReferenceEllipsoid = 23;
my_name_is = ellipsoid[ReferenceEllipsoid].ellipsoidName;
}
int coordinates::getlatlon(const double radlat, const double radlon) {
latitude = radlat;
lat = (latitude * 180.) / M_PI;
longitude = radlon;
lon = (longitude * 180.) / M_PI;
if (longitude > M_PI ) {
longitude -= (2.* M_PI);
lon -=360.,
this->LonH = "W";
}
else if (longitude < 0)
this->LonH = "W";
else
this->LonH = "E";
if (latitude < 0)
this->LatH = "S";
else
this->LatH = "N";
rad2grad(longitude, this->gr_lo, this->mi_lo, this->se_lo);
rad2grad(latitude, this->gr_la, this->mi_la, this->se_la);
flip();
return 1;
}
int coordinates::getlatlon(const long double& radlat, const long double& radlon) {
latitude = radlat;
lat = (latitude * 180.) / M_PI;
longitude = radlon;
lon = (longitude * 180.) / M_PI;
if (longitude > M_PI ) {
longitude -= (2.* M_PI);
lon -=360.,
this->LonH = "W";
}
else if (longitude < 0)
this->LonH = "W";
else
this->LonH = "E";
if (latitude < 0)
this->LatH = "S";
else
this->LatH = "N";
rad2grad(longitude, this->gr_lo, this->mi_lo, this->se_lo);
rad2grad(latitude, this->gr_la, this->mi_la, this->se_la);
flip();
return 1;
}
int coordinates::getlatlon(const int msec_lat, const int msec_lon) {
double radlat, radlon;
radlat = (msec_lat * M_PI) /( 3600000. * 180.);
radlon = (msec_lon * M_PI) /( 3600000. * 180.);
getlatlon(radlat, radlon);
return 1;
}
int coordinates::getlatlon(const string& slat, const string& slon) {
int lag;
int lam;
double las;
int log;
int lom;
double los;
// I do not use the this-> here because coordinates will be reset after reception!!
d_t_str2num(slat, ":", lag, lam, las);
d_t_str2num(slon, ":", log, lom, los);
return coordinates::getlatlon(lag, lam, los, LatH, log, lom, los, LonH);
}
void coordinates::get_msecs(int& msec_lat, int& msec_lon){
msec_lat = int ((latitude * 3600000. * 180.) / M_PI);
msec_lon = int ((longitude * 3600000. * 180.) / M_PI);
}
void coordinates::add(const int& lag, const int& lam, const double& las, const int& log, const int& lom, const double& los) {
this->gr_la += lag;
this->mi_la += lam;
this->se_la += las;
this->gr_lo += log;
this->mi_lo += lom;
this->se_lo += los;
}
int coordinates::getlatlon(const int& lag, const int& lam, const double& las, const string& LatH, const int& log, const int& lom, const double& los, const string& LonH) {
if ( (lag == INT_MAX) || (lam == INT_MAX) || (las == DBL_MAX) || (log == INT_MAX) || (lom == INT_MAX) || (los == DBL_MAX)) {
cerr << "coordinates::getlatlon-> at least on of the latitude / longitude entries is not valid " << endl;
cerr << lag << ":" << lam << ":" << las << " " << log << ":" << lom << ":" << los << endl;
return 0;
}
set_z();
this->gr_la = lag;
this->mi_la = lam;
this->se_la = las;
this->gr_lo = log;
this->mi_lo = lom;
this->se_lo = los;
this->LatH = LatH;
this->LonH = LonH;
latitude = grad2rad(this->gr_la, this->mi_la, this->se_la);
lat = lag + lam / 60. + las / 3600.;
longitude = grad2rad(this->gr_lo, this->mi_lo, this->se_lo);
lon = log + lom / 60. + los / 3600.;
// map 190 deg to 360 - 190 = -170 deg
// and indicate hemisphere
if (LatH == "x" && LonH == "x") {
if (longitude > M_PI ) {
longitude -= (2* M_PI);
lon -=360.,
this->LonH = "W";
}
else if (longitude < 0)
this->LonH = "W";
else
this->LonH = "E";
if (latitude < 0)
this->LatH = "S";
else
this->LatH = "N";
}
rad2grad(longitude, this->gr_lo, this->mi_lo, this->se_lo);
rad2grad(latitude, this->gr_la, this->mi_la, this->se_la);
flip();
return 1;
}
// next
int coordinates::getlatlon(const int lag, const int lam, const double las, const int log, const int lom,
double los, const int utmmer, const int gkmer, const int ell) {
if ( (lag == INT_MAX) || (lam == INT_MAX) || (las == DBL_MAX) || (log == INT_MAX) || (lom == INT_MAX) || (los == DBL_MAX)) {
cerr << "coordinates::getlatlon-> at least on of the latitude / longitude entries is not valid " << endl;
cerr << lag << ":" << lam << ":" << las << " " << log << ":" << lom << ":" << los << endl;
return 0;
}
set_z();
this->gr_la = lag;
this->mi_la = lam;
this->se_la = las;
this->gr_lo = log;
this->mi_lo = lom;
this->se_lo = los;
latitude = grad2rad(this->gr_la, this->mi_la, this->se_la);
lat = lag + lam / 60. + las / 3600.;
longitude = grad2rad(this->gr_lo, this->mi_lo, this->se_lo);
lon = log + lom / 60. + los / 3600.;
// map 190 deg to 360 - 190 = -170 deg
// and indicate hemisphere
if (LatH == "x" && LonH == "x") {
if (longitude > M_PI ) {
longitude -= (2. * M_PI);
lon -=360.,
this->LonH = "W";
}
else if (longitude < 0)
this->LonH = "W";
else
this->LonH = "E";
if (latitude < 0)
this->LatH = "S";
else
this->LatH = "N";
}
rad2grad(longitude, this->gr_lo, this->mi_lo, this->se_lo);
rad2grad(latitude, this->gr_la, this->mi_la, this->se_la);
flip();
getmeridian_ell(utmmer, gkmer, ell);
return 1;
}
/***************************************************************************
* *
* constructor with latitudes and longitude *
* and meridians and ellipsoid *
* *
* ns should be N or S *
* ew should be E or W *
***************************************************************************/
int coordinates::getlatlon(const int lag, const int lam, const double las, const char* ns,
const int log, const int lom, const double los, const char* ew, const int utmmer, const int gkmer, const int ell) {
if ( (lag == INT_MAX) || (lam == INT_MAX) || (las == DBL_MAX) || (log == INT_MAX) || (lom == INT_MAX) || (los == DBL_MAX)) {
cerr << "coordinates::getlatlon-> at least on of the latitude / longitude entries is not valid " << endl;
cerr << lag << ":" << lam << ":" << las << " " << log << ":" << lom << ":" << los << endl;
return 0;
}
set_z();
this->gr_la = lag;
this->mi_la = lam;
this->se_la = las;
this->gr_lo = log;
this->mi_lo = lom;
this->se_lo = los;
this->LonH.assign(ew, 1);
this->LatH.assign(ns, 1);
upper(this->LonH);
upper(this->LatH);
latitude = grad2rad(this->gr_la, this->mi_la, this->se_la);
lat = lag + lam / 60. + las / 3600.;
longitude = grad2rad(this->gr_lo, this->mi_lo, this->se_lo);
lon = log + lom / 60. + los / 3600.;
if (longitude > M_PI && this->LonH == "E") {
longitude = (2. * M_PI) - longitude;
lon = 360. -lon;
this->LonH = "W";
}
if (this->LonH == "W") {
longitude *= -1.;
lon *= -1.;
}
if (this->LatH == "S") {
latitude *= -1.;
lat *= -1.;
}
rad2grad(longitude, this->gr_lo, this->mi_lo, this->se_lo);
rad2grad(latitude, this->gr_la, this->mi_la, this->se_la);
flip();
getmeridian_ell(utmmer, gkmer, ell);
return 1;
}
/***************************************************************************
* *
* *
* *
* *
* *
* *
***************************************************************************/
int coordinates::getmeridian_ell(const int& utmmer, const int& gkmer, const int& ell = 23) {
if (utmmer == INT_MAX) {
cerr << "coordinates::getmeridian_ell -> at least utm meridian has to be 0, 6, 12 ..." << endl;
return 0;
}
if(utmmer != INT_MAX) {
if ( ( (utmmer + 3) % 6 ) == 0) {
this->utm_meridian = utmmer;
if (this->utm_meridian > 180)
this->utm_meridian -= 360;
} else
cerr << "coordinates::getmeridian -> UTM Merdian not valid, using auto calculation" << endl;
}
if (gkmer == INT_MAX) gk_meridian = this->utm_meridian;
if ( ( gkmer % 3 ) == 0)
gk_meridian = gkmer;
else
cerr << "coordinates::getmeridian -> Gauss Krueger Merdian not valid, using auto calculation" << endl;
if (gk_meridian < 0)
gk_meridian = 360 + gk_meridian;
if ( (ell != INT_MAX) && (ell < 24) && (ell > 0) )
ReferenceEllipsoid = ell;
else
ReferenceEllipsoid = 23;
my_name_is = ellipsoid[ReferenceEllipsoid].ellipsoidName;
return 1;
}
/***************************************************************************
* *
* *
* acknoledge *
* *
* *
* *
***************************************************************************/
void coordinates::akn() {
ios::fmtflags oldopts = cerr.flags();
cerr << "lat\x9\x9: " << setfill(' ') << setw(3) << this->gr_la << " " << setfill('0') << setw(2)
<< this->mi_la << " " << setfill('0') << setw(6) << this->se_la << " " << this->LatH;
cerr << " grad / rad : " << lat << " " << latitude << endl;
cerr << endl;
cerr << "lon\x9\x9: " << setfill(' ') << setw(3) << this->gr_lo << " " << setfill('0') << setw(2)
<< this->mi_lo <<" " << setfill('0') << setw(6) << this->se_lo << " " << this->LonH;
cerr << " grad / rad: " << lon << " " << longitude << endl;
cerr << endl;
cerr << "UTM and Gauss Krueger Merdian: " << this->utm_meridian << " " << gk_meridian << endl;
cerr << "Reference Ellipsoid : " << my_name_is << endl;
cerr << endl;
cerr.flags(oldopts);
}
/***************************************************************************
* *
* *
* *
* *
* *
* *
***************************************************************************/
void coordinates::display_utm() {
ios::fmtflags oldopts = cerr.flags();
cerr.setf(ios::showpoint);
cerr.precision(10);
cerr << "UTM Northing\x9: " << northing << endl;
cerr << "UTM Easting\x9: " << easting << endl;
cerr << "UTM Zone\x9: " << UTMzone << endl;
cerr << "UTM Meridian\x9: " << this->utm_meridian << endl;
cerr.flags(oldopts);
}
/***************************************************************************
* *
* *
* *
* *
* *
* *
***************************************************************************/
void coordinates::display_gauss() {
ios::fmtflags oldopts = cerr.flags();
cerr.setf(ios::showpoint);
cerr.precision(10);
cerr << "GK Hochwert\x9: " << hoch << endl;
cerr << "GK Rechtswert\x9: " << rechts << endl;
cerr << "GK Meridian\x9: " << gk_meridian << endl;
cerr.flags(oldopts);
}
void coordinates::display_lat_lon() {
cerr << "lat:\x9" << setfill(' ') << setw(3) << this->gr_la << ":" << setfill('0') << setw(2)
<< this->mi_la << ":" << setfill('0') << setw(2) << this->se_la << " " << this->LatH << endl;
cerr << "lon:\x9" << setfill(' ') << setw(3) << this->gr_lo << ":" << setfill('0') << setw(2)
<< this->mi_lo << ":" << setfill('0') << setw(2) << this->se_lo << " " << this->LonH << endl;
}
/***************************************************************************
* *
* *
* make values available *
* *
* missing check: did we already calculate? *
* *
***************************************************************************/
void coordinates::get_gauss(double& drechts, double& dhoch, int& iref_med) {
drechts = rechts;
dhoch = hoch;
iref_med = gk_meridian;
}
void coordinates::get_utm(double& dnorthing, double& deasting, int& izone,
int& iumeridian, char& cletter) {
dnorthing = northing;
deasting = easting;
iumeridian = this->utm_meridian;
izone = atoi(UTMzone.c_str());
cletter = UTMzone[UTMzone.size()-1];
}
/***************************************************************************
* if lat or lon are negative *
* set the this->gr_la and gra_lo values POSITIVE *
* and indicate with S and W *
* *
* *
* *
***************************************************************************/
void coordinates::flip() {
if (latitude < 0) {
this->gr_la *= -1;
this->mi_la *= -1;
this->se_la *= -1.;
this->LatH = "S";
}
if (longitude < 0) {
this->gr_lo *= -1;
this->mi_lo *= -1;
this->se_lo *= -1.;
this->LonH = "W";
}
}
/***************************************************************************
* *
* *
* *
* *
* *
* *
***************************************************************************/
void coordinates::geo2gauss () {
/*
c Die Laender der Bundesrepublik Deutschland verwenden als amtliche
c Bezugsflaeche das Bessel-Ellipsoid (s. /SCH81/, S.2).
c BESSEL-Ellipsoidkonstanlten:
c a : grosse Halbachse a = 6 377 397,155 m
c b : kleine Halbachse b = 6 356 078,963 m
c c : Polkruemmungsradius c = sqr(a)/b
c e': zweite numerische Exzentrizitaet e2 := e'2 = (a2-b2)/b2
internationales Ellipsoid anders definiert, etwa
a = 6378388
b = 6356911.946
f = 1/127 usw.
*/
long double a, b, c, e2, Q, ef2, ef4, ef6,
G, eta2, N, y, cL, dL, c2, t2;
// fix the problem that this algorithm works with 0...360 deg instead of
// -180 .. 180
// this applies also for the Meridian
long double temp_long = longitude;
long double three = 3.0;
if (longitude < 0)
temp_long = 2 * M_PI + longitude;
a = 6377397.15508;
b = 6356078.96290;
c = sqr(a) / b;
e2= (sqr(a) - sqr(b)) / sqr(b);
/* Abgeleitete Konstanten, s. /SCH81/, A.3.9, S.14
Q : meridianbogenlaenge vom Aequator bis zum Pol (meridianviertelkreis)
*/
Q = c * (1. -3./4. * e2 * (1. -15./16. * e2 * (1. -35./36. * e2 * (1.-63./64. * e2))));
ef2 = - c * 3./8. * e2 * (1. -5./4. * e2 * (1. -35./32. * e2 * (1.-21./20. *e2)));
ef4 = c * 15./256. * e2 * e2 * (1. -7./4. * e2 * (1. -21./16. * e2));
ef6 = - c * 35./3072. * pow(e2, three) * (1. -9./4. * e2);
// G : meridianbogenlAEnge zur gegebenen geographischen Breite latitude
G = Q * latitude + ef2 * sin(2. * latitude) + ef4 * sin(4. * latitude) +
ef6 * sin(6. * latitude);
c2 = sqr(cos(latitude));
t2 = sqr( tan(latitude));
eta2 = e2*c2;
//c N : Querkruemmungsradius, s. /SCH81/, A.3.6, S.11
N = c / sqrt(1. + eta2);
dL = temp_long * 180. / M_PI - gk_meridian;
cL = sqr( (dL * M_PI / 180.) ) * c2/2.;
y = M_PI / 180. * N * cos(latitude) * dL * (1. +cL/3. * (1. - t2 + eta2 + cL/10. * (5. - t2 * (18. - t2))));
rechts = gk_meridian / 3E-6 + 5E+5 + y;
hoch = G + N * tan(latitude) * cL *(1. + cL/6. * (5.- t2 + 9. * eta2));
}
/***********************************************************************************************/
/***************************************************************************
* *
* *
* *
* *
* *
* *
***************************************************************************/
void coordinates::gauss2geo() {
//rechtswert, hochwert, laenge & breite im Bogenmass als ergebnis
/*
c Unterprogramm zur Umrechnung von Gauss-Krueger-Koordinaten (rechts,
c hoch) in geographische Koordinaten (latitude, longitude).
c Die geographischen Koordinaten latitude und longitude (Breite und Laenge)
c werden im Bogenmass berechnet.
c Im Wesentlichen geschieht die Berechnung nach SCHOEDLBAUER, Albert,
c 'Rechenformeln und Rechenbeispiele zur Landesvermessung',
c Teil 1, Karlsruhe 1981: /SCH81/
c und Teil 2, Karlsruhe 1982: /SCH82/.
Konstanten werden im Programm mit extended Precision berechnet
CONST e2 = 6.719219E-3;
c = 6.398786849E6;
Q = 6366742.520261453;
f2 = 2.5112734435E-3;
f4 = 3.678654E-6;
f6 = 7.45559E-9;
s.o.
*/
long double a, b, c, e2, Q, eta2, N, y, c2, t2,
f2, f4, f6, lh, sigma, bf, yN;
long double three = 3.0;
a = 6377397.15508;
b = 6356078.96290;
c = sqr(a) / b;
e2 = (sqr(a) - sqr(b)) / sqr(b);
/*
c Abgeleitete Konstanten, siehe SCHOEDL., Teil 1, S.15
c Q : meridianbogenlaenge vom Aequator bis zum Pol (meridianviertelkreis)
*/
Q = c * (1. -3./ 4. * e2 * (1. -15./ 16. * e2 * (1. - 35./ 36. * e2 * (1. -63./ 64. * e2))));
f2 = 3E+0 / 8. * e2 * (1.-e2 / 2. * (1. -71./128. * e2));
f4 = 21./ 256. * e2 * e2 * (1. - e2);
f6 = 151.0 / 6144.0 * pow(e2, three); //{e2*e2*e2}
//c bf: Geographische Breite zur meridianbogenleange, s. /SCH81/, S.14f
sigma = hoch / Q;
bf = sigma + f2 * sin(2. * sigma) + f4 * sin(4. * sigma) + f6 * sin(6. * sigma);
c2 = sqr(cos(bf));
t2 = sqr(tan(bf));
eta2 = c2 * e2;
//c N : Querkruemmungsradius (/SCH81/, A.3.6, S.11)
N = c / (sqrt (1. + eta2));
if (rechts < 0.0001)
y = 0; // numerical error
// else y = rechts - floor(rechts / 1E6) * 1E6 - 5E5; // ! vgl. /SCH82/, B.2.1, S.79}
// floor rounds up?
else
y = rechts - long(rechts / 1E6) * 1E6 - 5E5; // ! vgl. /SCH82/, B.2.1, S.79}
yN = sqr(y/N)/2.;
//(c lh: Bezugsmeridian (in Bogenma�, s. /SCH82/, B.2.1, S.79
//{ lh = floor(rechts/1E6) * atanl(1E+0)/15;}
// lh = floor(rechts/1E6) * 3. * M_PI/180.;
// floor round up?
lh = long(rechts/1E6) * 3. * M_PI/180.;
latitude = bf - yN * tan(bf) * (1. + eta2 - yN/6. * (5. + 3. * t2 + 6. * eta2 * (1. - t2)
- yN * (4. + 3. * t2 * (2. + t2))));
longitude = lh + y/N/cos(bf) * (1. - yN/3. *
(1. + 2. * t2 + eta2 - yN / 10. * (5. + t2 * (28. + 24. * t2))));
if (longitude >= M_PI)
longitude -= (2 * M_PI);
lon = (longitude * 180.) / M_PI;
rad2grad(longitude, this->gr_lo, this->mi_lo, this->se_lo);
rad2grad(latitude, this->gr_la, this->mi_la, this->se_la);
flip();
}
/***********************************************************************************************/
/*Reference ellipsoids derived from Peter H. Dana's website-
http://www.utexas.edu/depts/grg/gcraft/notes/datum/elist.html
Department of Geography, University of Texas at Austin
Internet: pdana@mail.utexas.edu
3/22/95
Source
Defense Mapping Agency. 1987b. DMA Technical Report:
Supplement to Department of Defense World Geodetic System
1984 Technical Report. Part I and II. Washington, DC: Defense Mapping Agency
*/
/***************************************************************************
* *
* *
* *
* *
* *
* *
***************************************************************************/
void coordinates::geo2UTM() {
//converts lat/long to UTM coords. Equations from USGS Bulletin 1532
//East Longitudes are positive, West longitudes are negative.
//North latitudes are positive, South latitudes are negative
//Lat and Long are in decimal degrees
//Does not take into account thespecial UTM zones between 0 degrees and
//36 degrees longitude above 72 degrees latitude and a special zone 32
//between 56 degrees and 64 degrees north latitude
//Written by Chuck Gantz- chuck.gantz@globalstar.com
long double a = ellipsoid[ReferenceEllipsoid].EquatorialRadius;
long double eccSquared = ellipsoid[ReferenceEllipsoid].eccentricitySquared;
long double k0 = 0.9996;
int LongOrigin;
long double eccPrimeSquared;
long double N, T, C, A, M;
long double LatRad = latitude;
long double LongRad = longitude;
long double LongOriginRad;
if(lon > -6 && lon < 0)
LongOrigin = -3;
else if(lon < 6 && lon >= 0)
LongOrigin = 3; //arbitrarily set origin at 0 longitude to 3W
else if (lon == -180 || lon == 180)
LongOrigin = -177; // also forces at 180 deg to 177 W
else
LongOrigin = int(lon/6) * 6 + 3 * int(lon/6) / abs(int(lon / 6));
// if meridian was defined
if (this->utm_meridian != INT_MAX)
LongOrigin = this->utm_meridian;
else
this->utm_meridian = LongOrigin;
// set also Gauss Krueger meridian if not defined before
if (gk_meridian == INT_MAX)
gk_meridian = this->utm_meridian;
if (gk_meridian < 0 )
gk_meridian += 360;
LongOriginRad = LongOrigin * M_PI / 180.;
// char* utmzone;
//compute the UTM Zone from the latitude and longitude
// sprintf(UTMzone, "%d%c", int((lon + 180)/6) + 1, UTMLetterDesignator());
long ut = long(((lon + 180)/6) + 1);
UTMzone = num2str(ut);
UTMzone += UTMLetterDesignator();
eccPrimeSquared = (eccSquared)/(1-eccSquared);
N = a / sqrt(1. - eccSquared * sin(LatRad) * sin(LatRad));
T = tan(LatRad) * tan(LatRad);
C = eccPrimeSquared * cos(LatRad) * cos(LatRad);
A = cos(LatRad) * (LongRad - LongOriginRad);
M = a * ((1. - eccSquared/4. - 3. * eccSquared*eccSquared/64.
- 5. * eccSquared * eccSquared * eccSquared/256.) * LatRad
- (3. * eccSquared/8. + 3. * eccSquared * eccSquared/32.
+ 45. * eccSquared * eccSquared*eccSquared / 1024.) * sin(2. * LatRad)
+ (15. * eccSquared * eccSquared/256. + 45. * eccSquared * eccSquared * eccSquared/1024.)
* sin(4. * LatRad)
- (35. * eccSquared * eccSquared * eccSquared/3072.) * sin(6. * LatRad));
easting = (long double)(k0 * N * (A + (1 - T + C) * A * A * A/6.
+ (5. - 18. * T + T * T + 72. * C - 58. * eccPrimeSquared) * A * A * A * A * A/120.)
+ 500000.0);
northing = (long double)(k0 * (M + N * tan(LatRad) * (A * A/2. + (5. -T +9. * C + 4. * C *C )* A * A * A *A/24.
+ (61.- 58. * T + T * T + 600. * C - 330. * eccPrimeSquared) * A * A * A * A * A * A/720.)));
if(lat < 0)
northing += 10000000.0; //10000000 meter offset for southern hemisphere
}
/***************************************************************************
* *
* *
* *
* *
* *
* *
***************************************************************************/
char coordinates::UTMLetterDesignator() {
//This routine determines the correct UTM letter designator for the given latitude
//returns 'Z' if latitude is outside the UTM limits of 80N to 80S
//Written by Chuck Gantz- chuck.gantz@globalstar.com
char LetterDesignator;
if((80 >= lat) && (lat > 72))
LetterDesignator = 'X';
else if((72 >= lat) && (lat > 64))
LetterDesignator = 'W';
else if((64 >= lat) && (lat > 56))
LetterDesignator = 'V';
else if((56 >= lat) && (lat > 48))
LetterDesignator = 'U';
else if((48 >= lat) && (lat > 40))
LetterDesignator = 'T';
else if((40 >= lat) && (lat > 32))
LetterDesignator = 'S';
else if((32 >= lat) && (lat > 24))
LetterDesignator = 'R';
else if((24 >= lat) && (lat > 16))
LetterDesignator = 'Q';
else if((16 >= lat) && (lat > 8))
LetterDesignator = 'P';
else if(( 8 >= lat) && (lat >= 0))
LetterDesignator = 'N';
else if(( 0 >= lat) && (lat > -8))
LetterDesignator = 'M';
else if((-8>= lat) && (lat > -16))
LetterDesignator = 'L';
else if((-16 >= lat) && (lat > -24))
LetterDesignator = 'K';
else if((-24 >= lat) && (lat > -32))
LetterDesignator = 'J';
else if((-32 >= lat) && (lat > -40))
LetterDesignator = 'H';
else if((-40 >= lat) && (lat > -48))
LetterDesignator = 'G';
else if((-48 >= lat) && (lat > -56))
LetterDesignator = 'F';
else if((-56 >= lat) && (lat > -64))
LetterDesignator = 'E';
else if((-64 >= lat) && (lat > -72))
LetterDesignator = 'D';
else if((-72 >= lat) && (lat > -80))
LetterDesignator = 'C';
else
LetterDesignator = 'Z'; //This is here as an error flag to show that the Latitude is outside the UTM limits
return LetterDesignator;
}
/***************************************************************************
* *
* *
* *
* *
* *
* *
***************************************************************************/
void coordinates::UTM2geo() {
//converts UTM coords to lat/long. Equations from USGS Bulletin 1532
//East Longitudes are positive, West longitudes are negative.
//North latitudes are positive, South latitudes are negative
//Lat and Long are in decimal degrees.
//Does not take into account the special UTM zones between 0 degrees
//and 36 degrees longitude above 72 degrees latitude and a special
//zone 32 between 56 degrees and 64 degrees north latitude
//Written by Chuck Gantz- chuck.gantz@globalstar.com
long double k0 = 0.9996;
long double a = ellipsoid[ReferenceEllipsoid].EquatorialRadius;
long double eccSquared = ellipsoid[ReferenceEllipsoid].eccentricitySquared;
long double eccPrimeSquared;
long double e1 = (1-sqrt(1-eccSquared))/(1+sqrt(1-eccSquared));
long double N1, T1, C1, R1, D, M;
long double LongOrigin;
long double mu, phi1, phi1Rad;
long double x, y;
long double one_point_five = 1.5;
int ZoneNumber;
char* ZoneLetter;
int NorthernHemisphere; //1 for northern hemispher, 0 for southern
x = easting - 500000.0; //remove 500,000 meter offset for longitude
y = northing;
// ZoneNumber = strtoul(UTMzone.c_str(), &ZoneLetter, 10);
ZoneNumber = atoi(UTMzone.c_str());
ZoneLetter = &UTMzone[UTMzone.size()-1];
// cerr << ZoneNumber << " " << ZoneLetter << endl;
if((*ZoneLetter - 'N') >= 0)
NorthernHemisphere = 1; //point is in northern hemisphere
else {
NorthernHemisphere = 0; //point is in southern hemisphere
y -= 10000000.0; //remove 10,000,000 meter offset used for southern hemisphere
}
LongOrigin = ((ZoneNumber - 1) * 6 - 180) + 3; // +3 puts origin in middle of zone
eccPrimeSquared = (eccSquared)/(1. - eccSquared);
M = y / k0;
mu = M / (a * (1.- eccSquared/4. -3. * eccSquared*eccSquared/64.-
5 * eccSquared * eccSquared * eccSquared/256.));
phi1Rad = mu + (3. * e1/2. -27. *e1 * e1 * e1/32.)*sin(2. * mu)
+ (21. * e1 * e1/16. - 55. * e1 * e1 * e1 * e1/32.)*sin(4. * mu)
+(151. * e1 * e1 * e1/96.)*sin(6. * mu);
phi1 = phi1Rad * 180. / M_PI;
N1 = a / sqrt(1. - eccSquared * sin(phi1Rad) * sin(phi1Rad));
T1 = tan(phi1Rad) * tan(phi1Rad);
C1 = eccPrimeSquared * cos(phi1Rad) * cos(phi1Rad);
R1 = a * (1. - eccSquared) / pow((1. - eccSquared * sin(phi1Rad) * sin(phi1Rad)), one_point_five);
D = x/(N1 * k0);
latitude = phi1Rad - (N1*tan(phi1Rad)/R1)
* (D * D/2. - (5. + 3. * T1 + 10. * C1 - 4. * C1 * C1 - 9. * eccPrimeSquared)
* D * D * D * D/24.
+ (61. + 90. * T1 + 298. * C1 + 45.* T1 * T1 - 252. * eccPrimeSquared - 3. * C1 * C1)
* D * D * D * D * D * D/720.);
lat = latitude * 180. / M_PI;