-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsupport.js
2013 lines (1895 loc) · 84.6 KB
/
support.js
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
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
__author__ = "Craig Wieczorek"
__author__ = "John Wieczorek"
__contributor__ = "Marcelo Oyaneder Labarca"
__copyright__ = "Copyright 2021 Rauthiflor LLC"
__version__ = "support.js 2021-01-27T13:12-3:00"
*/
function convertDistance(){
var fromdist;
var todist;
var s = null;
var fromUnit = null;
var toUnit = null;
s = uiGetTextValue("TextFieldFromDistance");
if( s == null || s.length == 0 )
{
fromdist = 0;
uiSetLabelExplicit("TextFieldToDistance","0");
}
else
{
var num = null;
try
{
num = formatCalcDec.throwFormatError( s );
fromdist = num;
fromUnit = uiGetSelectedText("ChoiceFromDistUnits");
toUnit = uiGetSelectedText("ChoiceToDistUnits");
todist = convertLengthFromTo(fromdist,fromUnit,toUnit);
uiSetLabelExplicit("TextFieldToDistance", formatDistance.checkFormat(todist) );
}
catch ( exp )
{
errorDialog(g_properties.getPropertyLang("error.number.message"),
g_properties.getPropertyLang("error.number.title"), "TextFieldFromDistance", 0);
uiSetLabelExplicit("TextFieldFromDistance","0" );
uiSetLabelExplicit("TextFieldToDistance", "0" );
}
}
}
function convertScale(){
var fromdist;
var todist;
var scale = 1;
var s = null;
var fromUnit = null;
var toUnit = null;
var fromScale = null;
s = uiGetTextValue("TextFieldScaleFromDistance");
if( s == null || s.length == 0 )
{
fromdist = 0;
uiSetLabelExplicit("TextFieldScaleToDistance","0");
}
else
{
var num = null;
try
{
num = s;
fromdist = num;
fromUnit = uiGetSelectedText("ChoiceScaleFromDistUnits");
toUnit = uiGetSelectedText("ChoiceScaleToDistUnits");
fromScale = uiGetSelectedText("ChoiceScale");
s = fromScale.substring(2, fromScale.length);
if( s == null || s.length == 0 )
{
scale = 1;
}
else
{
num = s;
scale = num;
}
scalefactor = scale;
if(fromUnit == "mm" )
{
fromUnit = "m";
scalefactor/=1000.0;
}
else if( fromUnit == "cm" )
{
fromUnit = "m";
scalefactor/=100.0;
}
else if(fromUnit == "in")
{
fromUnit = "ft";
scalefactor/=12.0;
}
todist = scalefactor*convertLengthFromTo(fromdist,fromUnit,toUnit);
uiSetLabelExplicit("TextFieldScaleToDistance", formatDistance.checkFormat(todist) );
}
catch( exp )
{
errorDialog(g_properties.getPropertyLang("error.number.message"),
g_properties.getPropertyLang("error.number.title."), "TextFieldScaleFromDistance", 0);
uiSetLabelExplicit("TextFieldScaleFromDistance", "0" );
uiSetLabelExplicit("TextFieldScaleToDistance", "0" );
}
}
}
function testParameterLimits(){
if( !testLatLongLimits() )
{
console.log("ERROR: testParameterLimits() failed at testLatLongLimits");
return false;
}
if( !testHeadingLimits() )
{
console.log("ERROR: testParameterLimits() failed at testHeadingLimits()");
return false;
}
if( !testOffsetLimits() )
{
console.log("ERROR: testParameterLimits() failed at testOffsetLimits()");
return false;
}
if( !testOffsetEWLimits() )
{
console.log("ERROR: testParameterLimits() failed at testOffsetEWLimits()");
return false;
}
if( !testExtentLimits() )
{
console.log("ERROR: testParameterLimits() failed at testExtentLimits()");
return false;
}
if ( !testMeasurementErrorLimits() )
{
console.log("ERROR: testParameterLimits() failed at testMeasurementErrorLimits()");
return false;
}
return true;
}
function calculateResults(){
if( testParameterLimits() == false )
{
return;
}
translateCoords();
getNewCoordinates();
testResultCoordinates();
var declatstr = newdecimallatitude;
uiSetLabelExplicit("TextFieldCalcDecLat", declatstr );
var declongstr = newdecimallongitude;
uiSetLabelExplicit("TextFieldCalcDecLong", declongstr );
calculateMaxErrorDistance();
var errstr = maxerrordistance;
// uiSetLabelExplicit("TextFieldCalcErrorDist", errstr );
var distunits = uiGetSelectedText("ChoiceDistUnits");
var datumstr = uiGetSelectedText("ChoiceDatum");
var coordsysstr = uiGetSelectedText("ChoiceCoordSystem");
var coordprecisionstr = uiGetSelectedText("ChoiceLatPrecision");
var georeferencerstr = uiGetTextValue("TextFieldCalcGeoreferencer");
var currentDate = new Date();
var datestr = currentDate.toISOString()
var protocolstr = uiGetSelectedText("ChoiceProtocol");
var distanceprecisionstr = null;
var resultprecisionstr = "0.0000001"
if( uiIsVisible("ChoiceDistancePrecision") )
{
distanceprecisionstr = uiGetSelectedText("ChoiceDistancePrecision");
}
else
{
distanceprecisionstr = "";
}
var extentstr = null;
if( uiIsVisible("TextFieldExtent") )
{
extentstr = uiGetTextValue("TextFieldExtent");
}
else
{
extentstr = "";
}
declatstr = uiGetTextValue("TextFieldCalcDecLat");
declongstr = uiGetTextValue("TextFieldCalcDecLong");
if( declatstr.length > 9 )
{ // if there are floating point residuals in the calculation
declatstr = declatstr.substring(0,9);
}
if( declongstr.length > 10 )
{ // if there are floating point residuals in the calculation
declongstr = declongstr.substring(0,10);
}
// errstr = uiGetTextValue("TextFieldCalcErrorDist");
var errorinmeters = Math.round(
convertLengthFromTo( maxerrordistance,
uiGetSelectedText("ChoiceDistUnits"), "m" )
);
uiSetLabelExplicit("TextFieldCalcDecLat", formatCalcDec.checkFormat( newdecimallatitude ) );
uiSetLabelExplicit("TextFieldCalcDecLong",formatCalcDec.checkFormat( newdecimallongitude) );
// uiSetLabelExplicit("TextFieldCalcErrorDist", formatCalcError.checkFormat( maxerrordistance ) );
uiSetLabelExplicit("TextFieldCalcErrorDist", formatCalcError.checkFormat( errorinmeters ) );
uiSetLabelExplicit("TextFieldCalcDatum", datumstr);
uiSetLabelExplicit("TextFieldCalcPrecision", resultprecisionstr);
uiSetLabelExplicit("TextFieldCalcDate", datestr);
/***
Output meant to have tab-delimited output in the full result text box.
This can then be copied and pasted into a spreadsheet from the application.
Field order consists first of Darwin Core (http://rs.tdwg.org/dwc/) terms:
decimalLatitude, decimalLongitude, coordinateUncertaintyInMeters, geodeticDatum, verbatimCoordinateSystem
followed by additional parameters of the calculation:
Extent, MaxErrorDistance, DistanceUnits, DistancePrecision, CoordinatePrecision
The CoordinatePrecision here is the precision of the input coordinates, not of the final output. So this does
not match the meaning of the Darwin Core term coordinatePrecision.
***/
/*
var resultstr = formatCalcDec.checkFormat( newdecimallatitude ) + '\u0009' +
formatCalcDec.checkFormat( newdecimallongitude ) + '\u0009' +
formatCalcDec.checkFormat( errorinmeters ) + '\u0009' +
datumstr + '\u0009' +
coordsysstr + '\u0009' +
extentstr + '\u0009' +
formatCalcError.checkFormat( maxerrordistance ) + '\u0009' +
distunits + '\u0009' +
distanceprecisionstr + '\u0009' +
coordprecisionstr;
*/
var resultstr = formatCalcDec.checkFormat( newdecimallatitude ) + '\u0009' +
formatCalcDec.checkFormat( newdecimallongitude ) + '\u0009' +
datumstr + '\u0009' +
formatCalcDec.checkFormat( errorinmeters ) + '\u0009' +
resultprecisionstr + '\u0009' +
georeferencerstr + '\u0009' +
datestr + '\u0009' +
protocolstr;
uiSetLabelExplicit("TextFieldFullResult",resultstr);
return true;
}
function translateCoords(){
var ddeclat = 0;
var ddeclong = 0;
var num = null;
var s = null;
if( lastcoordsystem == 1 )
{ // was decimal degrees
s = uiGetTextValue("txtT2Dec_Lat");
if( s == null || s.length == 0 )
{
ddeclat = 0;
}
else
{
num = s;
ddeclat = num;
}
decimallatitude = ddeclat;
getDMSFromDecDegrees( decimallatitude );
uiSetLabelExplicit("txtT7Lat_DegDMS",formatDeg.checkFormat( degrees ) );
uiSetLabelExplicit("txtT7Lat_DegMM",formatDeg.checkFormat(degrees));
uiSetLabelExplicit("txtT7Lat_MinDMS",formatMin.checkFormat(minutes));
uiSetLabelExplicit("txtT7Lat_Sec",formatSec.checkFormat(seconds));
if( decimallatitude >= 0 )
{
uiSetSelectedValue("ChoiceLatDirDMS",g_properties.getPropertyLang("headings.n"));
uiSetSelectedValue("ChoiceLatDirMM",g_properties.getPropertyLang("headings.n"));
}
else
{
uiSetSelectedValue("ChoiceLatDirDMS",g_properties.getPropertyLang("headings.s"));
uiSetSelectedValue("ChoiceLatDirMM",g_properties.getPropertyLang("headings.s"));
}
var dmins = getDecimalMinutesFromMS( minutes, seconds );
uiSetLabelExplicit("txtT7Lat_MinMM",formatMinMM.checkFormat(dmins));
s = uiGetTextValue("txtT2Dec_Long");
if( s == null || s.length == 0 )
{
ddeclong = 0;
}
else
{
num = s;
ddeclong = num;
}
decimallongitude = ddeclong;
getDMSFromDecDegrees( decimallongitude );
uiSetLabelExplicit("txtT7Long_DegDMS",formatDeg.checkFormat(degrees));
uiSetLabelExplicit("txtT7Long_DegMM",formatDeg.checkFormat(degrees));
uiSetLabelExplicit("txtT7Long_MinDMS",formatMin.checkFormat(minutes));
uiSetLabelExplicit("txtT7Long_Sec",formatSec.checkFormat(seconds));
if( decimallongitude >= 0 )
{
uiSetSelectedValue("ChoiceLongDirDMS",g_properties.getPropertyLang("headings.e"));
uiSetSelectedValue("ChoiceLongDirMM",g_properties.getPropertyLang("headings.e"));
}
else
{
uiSetSelectedValue("ChoiceLongDirDMS",g_properties.getPropertyLang("headings.w"));
uiSetSelectedValue("ChoiceLongDirMM",g_properties.getPropertyLang("headings.w"));
}
dmins = getDecimalMinutesFromMS( minutes, seconds );
uiSetLabelExplicit("txtT7Long_MinMM",formatMinMM.checkFormat(dmins));
}
else if( lastcoordsystem == 2 )
{ // was degrees minutes seconds
num = uiGetTextValue("txtT7Lat_DegDMS");
degrees = num;
num = uiGetTextValue("txtT7Lat_MinDMS");
minutes = num;
var d = 0;
s = uiGetTextValue("txtT7Lat_Sec");
if( s == null || s.length == 0 )
{
d = 0;
}
else
{
num = s;
d = num;
}
seconds = d;
decimallatitude = Math.abs( getDecimalDegreesFromDMS(degrees, minutes, seconds) );
var SLatDirDMS = uiGetSelectedText("ChoiceLatDirDMS");
if( SLatDirDMS == g_properties.getPropertyLang("headings.s"))
{
decimallatitude *= -1.0;
}
uiSetLabelExplicit("txtT2Dec_Lat", formatDec.checkFormat(decimallatitude ));
uiSetLabelExplicit("txtT7Lat_DegMM",formatDeg.checkFormat(degrees));
decminutes = getDecimalMinutesFromMS( minutes, seconds );
uiSetLabelExplicit("txtT7Lat_MinMM",formatMinMM.checkFormat(decminutes));
num = uiGetTextValue("txtT7Long_DegDMS");
degrees = num;
num = uiGetTextValue("txtT7Long_MinDMS");
minutes = num;
s = uiGetTextValue("txtT7Long_Sec");
if( s == null || s.length == 0 )
{
d = 0;
}
else
{
num = s;
d = num;
}
seconds = d;
decimallongitude = Math.abs( getDecimalDegreesFromDMS(degrees, minutes, seconds) );
var SLongDirDMS = uiGetSelectedText("ChoiceLongDirDMS");
if( SLongDirDMS == g_properties.getPropertyLang("headings.w") )
{
decimallongitude *= -1;
}
uiSetLabelExplicit("txtT2Dec_Long", formatDec.checkFormat( decimallongitude ) );
uiSetLabelExplicit("txtT7Long_DegMM", formatDeg.checkFormat( degrees ));
decminutes = getDecimalMinutesFromMS( minutes, seconds );
uiSetLabelExplicit("txtT7Long_MinMM", formatMinMM.checkFormat( decminutes));
}
else if( lastcoordsystem == 3 )
{ // was degrees decimal minutes
num = uiGetTextValue("txtT7Lat_DegMM");
degrees = num;
//double m = 0;
var m = 0;
s = uiGetTextValue("txtT7Lat_MinMM");
if( s == null || s.length == 0 )
{
m = 0;
}
else
{
num = s;
m = num;
}
decminutes = m;
decimallatitude = Math.abs( getDecimalDegreesFromDegreesDecimalMinutes(degrees, decminutes) );
var SLatDirMM = uiGetSelectedText("ChoiceLatDirMM");
if( SLatDirMM == g_properties.getPropertyLang("headings.s"))
{
decimallatitude *= -1;
}
uiSetLabelExplicit("txtT2Dec_Lat",formatDec.checkFormat( decimallatitude));
getMSFromDecMinutes(decminutes);
uiSetLabelExplicit("txtT7Lat_DegDMS", formatDeg.checkFormat( degrees ));
uiSetLabelExplicit("txtT7Lat_MinDMS", formatMin.checkFormat( minutes ));
uiSetLabelExplicit("txtT7Lat_Sec", formatSec.checkFormat( seconds ));
uiSetSelectedValue("ChoiceLatDirDMS", uiGetSelectedText("ChoiceLatDirMM") );
num = uiGetTextValue("txtT7Long_DegMM");
degrees = num;
s = uiGetTextValue("txtT7Long_MinMM");
if( s == null || s.length == 0 )
{
m = 0;
}
else
{
num = s;
m = num;
}
decminutes = m;
decimallongitude = Math.abs( getDecimalDegreesFromDegreesDecimalMinutes(degrees, decminutes) );
var SLongDirMM = uiGetSelectedText("ChoiceLongDirMM");
if( SLongDirMM == g_properties.getPropertyLang("headings.w") )
{
decimallongitude *= -1;
}
uiSetLabelExplicit("txtT2Dec_Long", formatDec.checkFormat( decimallongitude ));
getMSFromDecMinutes(decminutes);
uiSetLabelExplicit("txtT7Long_DegDMS", formatDeg.checkFormat( degrees ));
uiSetLabelExplicit("txtT7Long_MinDMS", formatMin.checkFormat( minutes ));
uiSetLabelExplicit("txtT7Long_Sec", formatSec.checkFormat( seconds ));
uiSetSelectedValue( "ChoiceLongDirDMS", uiGetSelectedText( "ChoiceLongDirMM" ) );
}
else
{
console.log( "ERROR: translateCoords index not found :" + index + ":" )
}
var SCoordSystem = uiGetSelectedText("ChoiceCoordSystem");
var index = g_canonicalcoordsystems.indexOf(SCoordSystem);
lastcoordsystem = index+1;
}
function convertFromFeetTo( m, units ){
var newvalue = m;
// Convert from feet...
if( units =="m" )
{
newvalue *= 0.3048;
}
else if( units == "km" )
{
newvalue *= 0.0003048;
}
else if( units == "mi" )
{
newvalue *= 0.0001893939393939;
}
else if( units == "yds" )
{
newvalue *= 0.333333333;
}
else if( units == "nm" )
{
newvalue *= 0.00016458;
}
return newvalue;
}
function convertFromMetersTo( m, units ){
var newvalue = m;
// Convert from meters...
if( units == "ft" )
{
newvalue = m*3.28084;
}
else if( units == "km" )
{
newvalue = m*0.001;
}
else if( units == "mi" )
{
newvalue = m*0.000621371;
}
else if( units == "yds" )
{
newvalue = m*1.09361;
}
else if( units == "nm" )
{
newvalue = m*0.00053996;
}
return newvalue;
}
function convertLengthFromTo( length, from_units, to_units ){
if( from_units == null || to_units == null )
{
return 0.0;
}
var newvalue = length;
if( from_units == "m" )
{ // meters to...
if( to_units == "ft" )
{
newvalue *= 3.28084;
}
else if( to_units == "km" )
{
newvalue *= 0.001;
}
else if( to_units == "mi" )
{
newvalue *= 0.000621371;
}
else if( to_units == "yds" )
{
newvalue *= 1.09361;
}
else if( to_units == "nm" )
{
newvalue *= 0.00053996;
}
}
else if( from_units == "ft" )
{ // feet to...
if( to_units == "m" )
{
newvalue *= 0.3048;
}
else if( to_units == "km" )
{
newvalue *= 0.0003048;
}
else if( to_units == "mi" )
{
newvalue *= 0.0001893939393939;
}
else if( to_units == "yds" )
{
newvalue *= 0.333333333;
}
else if( to_units == "nm" )
{
newvalue *= 0.00016458;
}
}
else if( from_units == "km" )
{ // kilometers to...
if( to_units == "ft" )
{
newvalue *= 3280.84;
}
else if( to_units == "m" )
{
newvalue *= 1000.0;
}
else if( to_units == "mi" )
{
newvalue *= 0.621371;
}
else if( to_units == "yds" )
{
newvalue *= 1093.61;
}
else if( to_units == "nm" )
{
newvalue *= 0.53996;
}
}
else if( from_units == "mi" )
{ // miles to...
if( to_units == "ft" )
{
newvalue *= 5280.0;
}
else if( to_units == "m" )
{
newvalue *= 1609.3445;
}
else if( to_units == "km" )
{
newvalue *= 1.6093445;
}
else if( to_units == "yds" )
{
newvalue *= 1760.0;
}
else if( to_units == "nm" )
{
newvalue *= 0.86897624;
}
}
else if( from_units == "yds" )
{ // yards to...
if( to_units == "ft" )
{
newvalue *= 3.0;
}
else if( to_units == "m" )
{
newvalue *= 0.91440276;
}
else if( to_units == "km" )
{
newvalue *= 0.00091440276;
}
else if( to_units == "mi" )
{
newvalue *= 0.00056818182;
}
else if( to_units == "nm" )
{
newvalue *= 0.00049374;
}
}
else if( from_units == "nm" )
{ // nautical miles to...
if( to_units == "ft" )
{
newvalue *= 6076.1155;
}
else if( to_units == "m" )
{
newvalue *= 1852.0;
}
else if( to_units == "km" )
{
newvalue *= 1.852;
}
else if( to_units == "mi" )
{
newvalue *= 1.1507795;
}
else if( to_units == "yds" )
{
newvalue *= 2025.3718;
}
}
return newvalue;
}
function getDatumError(){
var s = uiGetSelectedText("ChoiceDatum");
if( s != null && s !== g_properties.getPropertyLang("datum.notrecorded") )
{
return 0.0;
}
var error = 0.0;
var latcells = 180/GRIDDEGREES;
var i = Math.round((Number(decimallatitude)+90)/GRIDDEGREES);
var j = Math.round((Number(decimallongitude)+180)/GRIDDEGREES);
var n = j*latcells + i;
error_in_m = datumerror[n];
// convert to current distance units
var distunitsstr = uiGetSelectedText("ChoiceDistUnits");
error = convertFromMetersTo( error_in_m, distunitsstr );
return error;
}
function getDecimalDegreesFromDegreesDecimalMinutes( d, m ){
var ddegs = Math.abs(m/60.0);
ddegs += Math.abs(d);
return ddegs;
}
function getDecimalDegreesFromDMS( d, m, s){
var ddegs = Math.abs(s/3600.0);
ddegs += Math.abs(m/60.0);
ddegs += Math.abs(d);
return ddegs;
}
function getDecimalMinutesFromMS( m, s){
var dmins = Math.abs(s/60.0);
dmins += Math.abs(m);
return dmins;
}
function getDirectionError( offset, disterr ){
var alpha = 1.0; // direction precision, in degrees.
var dir = uiGetSelectedText("ChoiceDirection");
var index = g_canonicalheadings.indexOf(dir);
if( index<4 )
{
alpha=45.0;
}
else if( index<8 )
{
alpha=22.5;
}
else if( index<16 )
{
alpha=11.25;
}
else if( index<32 )
{
alpha=5.625;
}
var x = offset*Math.cos(alpha*Math.PI/180.0);
var y = offset*Math.sin(alpha*Math.PI/180.0);
var xp = offset+disterr;
var error = Math.sqrt( Math.pow(xp-x,2) + Math.pow(y,2) );
return error; // error is in whatever units are selected.
}
function getDistancePrecisionError(){
var error = 0.0;
var precstr = uiGetSelectedText("ChoiceDistancePrecision");
var units = uiGetSelectedText("ChoiceDistUnits");
if( precstr == "100 " + units )
{
error = 50.0;
}
else if( precstr == "10 " + units )
{
error = 5.0;
}
else if( precstr == "1 " + units )
{
error = 0.5;
}
else if( precstr == "1/2 " + units )
{
error = 0.25;
}
else if( precstr == "1/3 " + units )
{
error = 0.1666667;
}
else if( precstr == "1/4 " + units )
{
error = 0.125;
}
else if( precstr == "1/8 " + units )
{
error = 0.0625;
}
else if( precstr == "1/10 " + units )
{
error = 0.05;
}
else if( precstr == "1/100 " + units )
{
error = 0.005;
}
return error;
}
function getDMSFromDecDegrees( dval )
{ // 40.17, -67.1
lastdecimaldegrees=dval;
if ( dval < 0 ){
sign = -1; // 1, -1
}
else
{
sign = 1;
}
seconds = sign*Number(dval)*3600.0; // 14461.2, 24156
var degs = Math.floor(seconds/3600); // 40.17, 67.1
degrees = degs; // 40, 67
seconds -= degrees*3600.0; // 61.2, 36.0
var mins = seconds/60.0; // 1.02, 0.6
decminutes = mins;
minutes = Math.floor(mins); // 1, 0
seconds -= minutes*60.0; // 1.2, 36.0
var secsAsInt = getNearestInt( seconds*1000.0 );
seconds=secsAsInt/1000.0;
while ( seconds >= 60.0 )
{
seconds -= 60.0;
minutes++;
}
if( Math.abs(seconds-60.0) < 0.01 )
{
seconds = 0.0;
minutes++;
}
while ( minutes >= 60 )
{
minutes -= 60;
degrees++;
}
}
function getEllipsoidCode( datumstr ){
if( datumstr == "(WGS84) World Geodetic System 1984") return "WE";
if( datumstr == "Abidjan 1987") return "CD";
if( datumstr == "Accra") return "WO";
if( datumstr == "Aden 1925") return "CD";
if( datumstr == "Adindan") return "CD";
if( datumstr == "Afgooye") return "KA";
if( datumstr == "Ain el Abd 1970") return "IN";
if( datumstr == "Airy 1830 ellipsoid") return "AA";
if( datumstr == "Airy Modified 1849 ellipsoid") return "AM";
if( datumstr == "Alaska (NAD27)") return "CC";
if( datumstr == "Alaska/Canada (NAD27)") return "CC";
if( datumstr == "Albanian 1987") return "KA";
if( datumstr == "American Samoa 1962") return "CC";
if( datumstr == "Amersfoort") return "BR";
if( datumstr == "Ammassalik 1958") return "IN";
if( datumstr == "Anguilla 1957") return "CD";
if( datumstr == "Anna 1 Astro 1965") return "AN";
if( datumstr == "Antigua Island Astro 1943") return "CD";
if( datumstr == "Aratu") return "IN";
if( datumstr == "Arc 1950 mean") return "CD";
if( datumstr == "Arc 1960 mean") return "CD";
if( datumstr == "Ascension Island 1958") return "IN";
if( datumstr == "Astro Beacon \"E\" 1945") return "IN";
if( datumstr == "Astro DOS 71/4") return "IN";
if( datumstr == "Astro Tern Island (FRIG) 1961") return "IN";
if( datumstr == "Astronomic Station No. 1 1951") return "IN";
if( datumstr == "Astronomic Station No. 2 1951, Truk Island") return "IN";
if( datumstr == "Astronomic Station Ponape 1951") return "IN";
if( datumstr == "Astronomical Station 1952") return "IN";
if( datumstr == "Australian Antarctic Datum 1998") return "RF";
if( datumstr == "(AGD66) Australian Geodetic Datum 1966") return "AN";
if( datumstr == "(AGD84) Australian Geodetic Datum 1984") return "AN";
if( datumstr == "Australian National ellipsoid") return "AN";
if( datumstr == "Autonomous Regions of Portugal 2008") return "RF";
if( datumstr == "Average Terrestrial System 1977 ellipsoid") return "AV";
if( datumstr == "Ayabelle Lighthouse") return "CD";
if( datumstr == "Azores Central Islands 1948") return "IN";
if( datumstr == "Azores Central Islands 1995") return "IN";
if( datumstr == "Azores Occidental Islands 1939") return "IN";
if( datumstr == "Azores Oriental Islands 1940") return "IN";
if( datumstr == "Azores Oriental Islands 1995") return "IN";
if( datumstr == "Bahamas (NAD27)") return "CC";
if( datumstr == "Barbados 1938") return "CD";
if( datumstr == "Batavia") return "BR";
if( datumstr == "Beduaram") return "CD";
if( datumstr == "Beijing 1954") return "KA";
if( datumstr == "Bekaa Valley 1920 (IGN)") return "CD";
if( datumstr == "Bellevue (IGN)") return "IN";
if( datumstr == "Bermuda 1957") return "CC";
if( datumstr == "Bermuda 2000") return "WE";
if( datumstr == "Bessel 1841 ellipsoid (Namibia)") return "BN";
if( datumstr == "Bessel 1841 ellipsoid (non-Namibia)") return "BR";
if( datumstr == "Bessel Modified ellipsoid") return "BM";
if( datumstr == "Bhutan National Geodetic Datum") return "RF";
if( datumstr == "Bioko") return "IN";
if( datumstr == "Bissau") return "IN";
if( datumstr == "Bogota 1975") return "IN";
if( datumstr == "Bukit Rimpah") return "BN";
if( datumstr == "Bulgaria Geodetic System 2005") return "RF";
if( datumstr == "Cadastre 1997") return "IN";
if( datumstr == "Camacupa") return "CD";
if( datumstr == "Camp Area Astro") return "IN";
if( datumstr == "Campo Inchauspe") return "IN";
if( datumstr == "Canada Mean (NAD27)") return "CC";
if( datumstr == "Canal Zone (NAD27)") return "CC";
if( datumstr == "Canton Astro 1966") return "IN";
if( datumstr == "Cape") return "CD";
if( datumstr == "Cape Canaveral mean") return "CC";
if( datumstr == "Caribbean (NAD27)") return "CC";
if( datumstr == "Carthage") return "CD";
if( datumstr == "Cayman Islands Geodetic Datum 2011") return "RF";
if( datumstr == "Central America (NAD27)") return "CC";
if( datumstr == "Centre Spatial Guyanais 1967") return "IN";
if( datumstr == "CH1903") return "BR";
if( datumstr == "CH1903+") return "BR";
if( datumstr == "Chatham Island Astro 1971") return "IN";
if( datumstr == "Chatham Islands Datum 1979") return "IN";
if( datumstr == "Chua Astro") return "IN";
if( datumstr == "Clarke 1858 ellipsoid") return "CE";
if( datumstr == "Clarke 1866 ellipsoid") return "CC";
if( datumstr == "Clarke 1880 ellipsoid") return "CD";
if( datumstr == "Clarke 1880 (Benoit) ellipsoid") return "CB";
if( datumstr == "Clarke 1880 (international foot) ellipsoid") return "CI";
if( datumstr == "Co-Ordinate System 1937 of Estonia") return "BR";
if( datumstr == "Cocos Islands 1965") return "AF";
if( datumstr == "Combani 1950") return "IN";
if( datumstr == "Conakry 1905") return "CD";
if( datumstr == "Congo 1960 Pointe Noire") return "CD";
if( datumstr == "Corrego Alegre 1961") return "IN";
if( datumstr == "Corrego Alegre 1970-72") return "IN";
if( datumstr == "Costa Rica 2005") return "WE";
if( datumstr == "Cuba (NAD27)") return "CC";
if( datumstr == "Croatian Terrestrial Reference System") return "RF";
if( datumstr == "Cyprus") return "IN";
if( datumstr == "Cyprus Geodetic Reference System 1993") return "WE";
if( datumstr == "Dabola 1981") return "CD";
if( datumstr == "Danish 1876") return "DN";
if( datumstr == "Datum 73") return "IN";
if( datumstr == "Datum Geodesi Nasional 1995") return "WE";
if( datumstr == "Dealul Piscului 1930") return "IN";
if( datumstr == "Deception Island") return "CD";
if( datumstr == "Deir ez Zor") return "CD";
if( datumstr == "Deutsches Hauptdreiecksnetz") return "BR";
if( datumstr == "Diego Garcia 1969") return "IN";
if( datumstr == "Djakarta (Batavia)") return "BR";
if( datumstr == "DOS 1968") return "IN";
if( datumstr == "Dominica 1945") return "CD";
if( datumstr == "Douala 1948") return "IN";
if( datumstr == "Easter Island 1967") return "IN";
if( datumstr == "Egypt 1907") return "HE";
if( datumstr == "Egypt Gulf of Suez S-650 TL") return "HE";
if( datumstr == "Estonia 1992") return "RF";
if( datumstr == "Estonia 1997") return "RF";
if( datumstr == "European 1950") return "IN";
if( datumstr == "European 1950 mean") return "IN";
if( datumstr == "European Datum 1950(1977)") return "IN";
if( datumstr == "European 1979 mean") return "IN";
if( datumstr == "European Datum 1987") return "IN";
if( datumstr == "European Libyan Datum 1979") return "IN";
if( datumstr == "European Terrestrial Reference System 1989") return "RF";
if( datumstr == "Everest ellipsoid (Brunei, Sabah, Sarawak)") return "EB";
if( datumstr == "Everest ellipsoid (W. Malaysia, Singapore 1948)") return "EE";
if( datumstr == "Everest 1830 (1937 Adjustment) ellipsoid India") return "EA";
if( datumstr == "Everest India 1856 ellipsoid") return "EC";
if( datumstr == "Everest 1830 (1962 Definition) ellipsoid India") return "EG";
if( datumstr == "Everest 1830 (1975 Definition) ellipsoid India") return "EH";
if( datumstr == "Everest Pakistan ellipsoid") return "EF";
if( datumstr == "Everest W. Malaysia 1969 ellipsoid") return "ED";
if( datumstr == "Fahud") return "CD";
if( datumstr == "Fatu Iva 72") return "IN";
if( datumstr == "Fehmarnbelt Datum 2010") return "RF";
if( datumstr == "Fiji 1956") return "IN";
if( datumstr == "Fiji Geodetic Datum 1986") return "WD";
if( datumstr == "Final Datum 1958") return "CD";
if( datumstr == "Finnish Nautical Chart") return "IN";
if( datumstr == "Fort Marigot") return "IN";
if( datumstr == "Fort Thomas 1955") return "CD";
if( datumstr == "Gambia") return "CD";
if( datumstr == "Gan 1970") return "IN";
if( datumstr == "Gandajika Base") return "IN";
if( datumstr == "Gan 1970") return "IN";
if( datumstr == "Geocentric Datum Brunei Darussalam 2009") return "RF";
if( datumstr == "Geocentric Datum of Australia 1994") return "RF";
if( datumstr == "Geocentric Datum of Australia 2020") return "RF";
if( datumstr == "Geocentric Datum of Korea") return "RF";
if( datumstr == "Geodetic Datum of 1965") return "AM";
if( datumstr == "Geodetic Datum 1949") return "IN";
if( datumstr == "Geodetic Reference System 1967 ellipsoid") return "RE";
if( datumstr == "Geodetic Reference System 1967 Modified ellipsoid") return "RD";
if( datumstr == "Geodetic Reference System 1980 ellipsoid") return "RF";
if( datumstr == "Ghana") return "WE";
if( datumstr == "Graciosa Base SW 1948") return "IN";
if( datumstr == "Grand Cayman Geodetic Datum 1959") return "CC";
if( datumstr == "Grand Comoros") return "IN";
if( datumstr == "Greek Geodetic Reference System 1987") return "RF";
if( datumstr == "Greenland (NAD27)") return "CC";
if( datumstr == "Greenland 1996") return "RF";
if( datumstr == "Grenada 1953") return "CD";
if( datumstr == "Guadeloupe 1948") return "IN";
if( datumstr == "Guam 1963") return "CC";
if( datumstr == "Gulshan 303") return "EA";
if( datumstr == "Gunung Segara") return "BN";
if( datumstr == "Gunung Serindung 1962") return "WE";
if( datumstr == "GUX 1 Astro") return "IN";
if( datumstr == "Hanoi 1972") return "KA";
if( datumstr == "Hartebeesthoek94") return "WE";
if( datumstr == "Helle 1954") return "IN";
if( datumstr == "Helmert 1906 ellipsoid") return "HE";
if( datumstr == "Herat North") return "IN";
if( datumstr == "Hito XVIII 1963") return "IN";
if( datumstr == "Hjorsey 1955") return "IN";
if( datumstr == "Hong Kong 1963(67)") return "IN";