-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwgs84_ch1903.php
executable file
·110 lines (80 loc) · 2.75 KB
/
wgs84_ch1903.php
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
<?php
// Source: http://www.swisstopo.admin.ch/internet/swisstopo/en/home/topics/survey/sys/refsys/projections.html (see PDFs under "Documentation")
// Updated 9 dec 2014
// Please validate your results with NAVREF on-line service: http://www.swisstopo.admin.ch/internet/swisstopo/en/home/apps/calc/navref.html (difference ~ 1-2m)
// Convert WGS lat/long (° dec) to CH y
function WGStoCHy($lat, $long) {
// Converts decimal degrees sexagesimal seconds
$lat = DECtoSEX($lat);
$long = DECtoSEX($long);
// Auxiliary values (% Bern)
$lat_aux = ($lat - 169028.66)/10000;
$long_aux = ($long - 26782.5)/10000;
// Process Y
$y = 600072.37
+ 211455.93 * $long_aux
- 10938.51 * $long_aux * $lat_aux
- 0.36 * $long_aux * pow($lat_aux,2)
- 44.54 * pow($long_aux,3);
return $y;
}
// Convert WGS lat/long (° dec) to CH x
function WGStoCHx($lat, $long) {
// Converts decimal degrees sexagesimal seconds
$lat = DECtoSEX($lat);
$long = DECtoSEX($long);
// Auxiliary values (% Bern)
$lat_aux = ($lat - 169028.66)/10000;
$long_aux = ($long - 26782.5)/10000;
// Process X
$x = 200147.07
+ 308807.95 * $lat_aux
+ 3745.25 * pow($long_aux,2)
+ 76.63 * pow($lat_aux,2)
- 194.56 * pow($long_aux,2) * $lat_aux
+ 119.79 * pow($lat_aux,3);
return $x;
}
// Convert CH y/x to WGS lat
function CHtoWGSlat($y, $x) {
// Converts military to civil and to unit = 1000km
// Auxiliary values (% Bern)
$y_aux = ($y - 600000)/1000000;
$x_aux = ($x - 200000)/1000000;
// Process lat
$lat = 16.9023892
+ 3.238272 * $x_aux
- 0.270978 * pow($y_aux,2)
- 0.002528 * pow($x_aux,2)
- 0.0447 * pow($y_aux,2) * $x_aux
- 0.0140 * pow($x_aux,3);
// Unit 10000" to 1 " and converts seconds to degrees (dec)
$lat = $lat * 100/36;
return $lat;
}
// Convert CH y/x to WGS long
function CHtoWGSlong($y, $x) {
// Converts military to civil and to unit = 1000km
// Auxiliary values (% Bern)
$y_aux = ($y - 600000)/1000000;
$x_aux = ($x - 200000)/1000000;
// Process long
$long = 2.6779094
+ 4.728982 * $y_aux
+ 0.791484 * $y_aux * $x_aux
+ 0.1306 * $y_aux * pow($x_aux,2)
- 0.0436 * pow($y_aux,3);
// Unit 10000" to 1 " and converts seconds to degrees (dec)
$long = $long * 100/36;
return $long;
}
// Convert DEC angle to SEX DMS
function DECtoSEX($angle) {
// Extract DMS
$deg = intval( $angle );
$min = intval( ($angle-$deg)*60 );
$sec = ((($angle-$deg)*60)-$min)*60;
// Result in sexagesimal seconds
return $sec + $min*60 + $deg*3600;
}
?>