@@ -11,7 +11,9 @@ discard block |
||
11 | 11 | print '<h1>'._("Geoid Height Calculator").'</h1>'; |
12 | 12 | print '</div>'; |
13 | 13 | print '<p>Not available</p>'; |
14 | - if (isset($globalDebug) && $globalDebug) echo '<p>'.$e.'</p>'; |
|
14 | + if (isset($globalDebug) && $globalDebug) { |
|
15 | + echo '<p>'.$e.'</p>'; |
|
16 | + } |
|
15 | 17 | require_once('footer.php'); |
16 | 18 | } |
17 | 19 | $title = _("Geoid Height Calculator"); |
@@ -68,8 +70,11 @@ discard block |
||
68 | 70 | print '<div class="col-sm-6">'.round($altitude-$geoid,3).'</div>'; |
69 | 71 | } |
70 | 72 | print '<div class="col-sm-6"><b>Earth Gravity Model</b></div>'; |
71 | - if (isset($globalGeoidSource) && $globalGeoidSource != '') $geoidsource = $globalGeoidSource; |
|
72 | - else $geoidsource = 'EGM96-15'; |
|
73 | + if (isset($globalGeoidSource) && $globalGeoidSource != '') { |
|
74 | + $geoidsource = $globalGeoidSource; |
|
75 | + } else { |
|
76 | + $geoidsource = 'EGM96-15'; |
|
77 | + } |
|
73 | 78 | print '<div class="col-sm-6">'.$geoidsource.'</div>'; |
74 | 79 | print '</div>'; |
75 | 80 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * Translated to PHP of GeographicLib/src/Geoid.cpp |
12 | 12 | * by Ycarus <[email protected]> in 2017 |
13 | 13 | */ |
14 | -class GeoidHeight { |
|
14 | +class GeoidHeight { |
|
15 | 15 | private $c0 = 240; |
16 | 16 | private $c3 = [[9, -18, -88, 0, 96, 90, 0, 0, -60, -20], [-9, 18, 8, 0, -96, 30, 0, 0, 60, -20], [9, -88, -18, 90, 96, 0, -20, -60, 0, 0], [186, -42, -42, -150, -96, -150, 60, 60, 60, 60], [54, 162, -78, 30, -24, -90, -60, 60, -60, 60], [-9, -32, 18, 30, 24, 0, 20, -60, 0, 0], [-9, 8, 18, 30, -96, 0, -20, 60, 0, 0], [54, -78, 162, -90, -24, 30, 60, -60, 60, -60], [-54, 78, 78, 90, 144, 90, -60, -60, -60, -60], [9, -8, -18, -30, -24, 0, 20, 60, 0, 0], [-9, 18, -32, 0, 24, 30, 0, 0, -60, 20], [9, -18, -8, 0, -24, -30, 0, 0, 60, 20]]; |
17 | 17 | private $c0n = 372; |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | private $v10 = null; |
35 | 35 | private $v11 = null; |
36 | 36 | |
37 | - public function __construct($name='') { |
|
37 | + public function __construct($name = '') { |
|
38 | 38 | global $globalGeoidSource; |
39 | 39 | //if ($name == '') $name = dirname(__FILE__).'/../install/tmp/egm2008-1.pgm'; |
40 | 40 | if ($name == '') { |
@@ -45,35 +45,35 @@ discard block |
||
45 | 45 | if (file_exists($name) === FALSE) { |
46 | 46 | throw new Exception($name." doesn't exist"); |
47 | 47 | } |
48 | - $f = @fopen($name,"r"); |
|
48 | + $f = @fopen($name, "r"); |
|
49 | 49 | if ($f === FALSE) { |
50 | 50 | throw new Exception("Can't open ".$name); |
51 | 51 | } |
52 | - $line = fgets($f,4096); |
|
52 | + $line = fgets($f, 4096); |
|
53 | 53 | if (trim($line) != 'P5') { |
54 | 54 | throw new Exception('No PGM header'); |
55 | 55 | } |
56 | 56 | $headerlen = strlen($line); |
57 | 57 | while (true) { |
58 | - $line = fgets($f,4096); |
|
58 | + $line = fgets($f, 4096); |
|
59 | 59 | if ((strlen($line) == 0)) { |
60 | 60 | throw new Exception('EOF before end of file header'); |
61 | 61 | } |
62 | 62 | $headerlen += strlen($line); |
63 | - if (strpos($line,'# Offset ') !== FALSE) { |
|
63 | + if (strpos($line, '# Offset ') !== FALSE) { |
|
64 | 64 | $this->offset = substr($line, 9); |
65 | - } else if (strpos($line,'# Scale ') !== FALSE) { |
|
65 | + } else if (strpos($line, '# Scale ') !== FALSE) { |
|
66 | 66 | $this->scale = substr($line, 8); |
67 | - } else if ((strpos($line,'#') === FALSE)) { |
|
68 | - list($this->width, $this->height) = preg_split('/\s+/',$line); |
|
67 | + } else if ((strpos($line, '#') === FALSE)) { |
|
68 | + list($this->width, $this->height) = preg_split('/\s+/', $line); |
|
69 | 69 | break; |
70 | 70 | } |
71 | 71 | } |
72 | - $line = fgets($f,4096); |
|
72 | + $line = fgets($f, 4096); |
|
73 | 73 | $headerlen += strlen($line); |
74 | - $levels = (int)$line; |
|
75 | - $this->width = (int)$this->width; |
|
76 | - $this->height = (int)$this->height; |
|
74 | + $levels = (int) $line; |
|
75 | + $this->width = (int) $this->width; |
|
76 | + $this->height = (int) $this->height; |
|
77 | 77 | if (($levels != 65535)) { |
78 | 78 | throw new Exception('PGM file must have 65535 gray levels ('.$levels.')'); |
79 | 79 | } |
@@ -88,42 +88,42 @@ discard block |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | $fullsize = filesize($name); |
91 | - if ((($fullsize - $headerlen) != (($this->width * $this->height) * 2))) { |
|
91 | + if ((($fullsize - $headerlen) != (($this->width*$this->height)*2))) { |
|
92 | 92 | throw new Exception('File has the wrong length'); |
93 | 93 | } |
94 | 94 | |
95 | 95 | $this->headerlen = $headerlen; |
96 | - $this->raw= $f; |
|
97 | - $this->rlonres = ($this->width / 360.0); |
|
98 | - $this->rlatres = (($this->height - 1) / 180.0); |
|
96 | + $this->raw = $f; |
|
97 | + $this->rlonres = ($this->width/360.0); |
|
98 | + $this->rlatres = (($this->height - 1)/180.0); |
|
99 | 99 | } |
100 | 100 | |
101 | - private function _rawval($ix,$iy) { |
|
101 | + private function _rawval($ix, $iy) { |
|
102 | 102 | if (($iy < 0)) { |
103 | 103 | $iy = -$iy; |
104 | - $ix += ($this->width / 2); |
|
104 | + $ix += ($this->width/2); |
|
105 | 105 | } else if (($iy >= $this->height)) { |
106 | - $iy = ((2 * ($this->height - 1)) - $iy); |
|
107 | - $ix += ($this->width / 2); |
|
106 | + $iy = ((2*($this->height - 1)) - $iy); |
|
107 | + $ix += ($this->width/2); |
|
108 | 108 | } |
109 | 109 | if (($ix < 0)) { |
110 | 110 | $ix += $this->width; |
111 | 111 | } else if (($ix >= $this->width)) { |
112 | 112 | $ix -= $this->width; |
113 | 113 | } |
114 | - $k = ((($iy * $this->width) + $ix) * 2) + $this->headerlen; |
|
115 | - fseek($this->raw,$k); |
|
116 | - return unpack('n',fread($this->raw,2))[1]; |
|
114 | + $k = ((($iy*$this->width) + $ix)*2) + $this->headerlen; |
|
115 | + fseek($this->raw, $k); |
|
116 | + return unpack('n', fread($this->raw, 2))[1]; |
|
117 | 117 | } |
118 | 118 | |
119 | - public function get($lat,$lon,$cubic=true) { |
|
119 | + public function get($lat, $lon, $cubic = true) { |
|
120 | 120 | if (($lon < 0)) { |
121 | 121 | $lon += 360; |
122 | 122 | } |
123 | - $fy = ((90 - $lat) * $this->rlatres); |
|
124 | - $fx = ($lon * $this->rlonres); |
|
125 | - $iy = (int)$fy; |
|
126 | - $ix = (int)$fx; |
|
123 | + $fy = ((90 - $lat)*$this->rlatres); |
|
124 | + $fx = ($lon*$this->rlonres); |
|
125 | + $iy = (int) $fy; |
|
126 | + $ix = (int) $fx; |
|
127 | 127 | $fx -= $ix; |
128 | 128 | $fy -= $iy; |
129 | 129 | $t = array(); |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | $c3x = $this->c3; |
151 | 151 | $c0x = $this->c0; |
152 | 152 | } |
153 | - for ($i = 0; $i < 10;++$i) { |
|
153 | + for ($i = 0; $i < 10; ++$i) { |
|
154 | 154 | $t[$i] = 0; |
155 | 155 | for ($j = 0; $j < 12; ++$j) { |
156 | 156 | $t[$i] += $v[$j]*$c3x[$j][$i]; |
@@ -161,13 +161,13 @@ discard block |
||
161 | 161 | $this->t = $t; |
162 | 162 | } else $t = $this->t; |
163 | 163 | if (!($cubic)) { |
164 | - $a = (((1 - $fx) * $this->v00) + ($fx * $this->v01)); |
|
165 | - $b = (((1 - $fx) * $this->v10) + ($fx * $this->v11)); |
|
166 | - $h = (((1 - $fy) * $a) + ($fy * $b)); |
|
164 | + $a = (((1 - $fx)*$this->v00) + ($fx*$this->v01)); |
|
165 | + $b = (((1 - $fx)*$this->v10) + ($fx*$this->v11)); |
|
166 | + $h = (((1 - $fy)*$a) + ($fy*$b)); |
|
167 | 167 | } else { |
168 | - $h = (($t[0] + ($fx * ($t[1] + ($fx * ($t[3] + ($fx * $t[6])))))) + ($fy * (($t[2] + ($fx * ($t[4] + ($fx * $t[7])))) + ($fy * (($t[5] + ($fx * $t[8])) + ($fy * $t[9])))))); |
|
168 | + $h = (($t[0] + ($fx*($t[1] + ($fx*($t[3] + ($fx*$t[6])))))) + ($fy*(($t[2] + ($fx*($t[4] + ($fx*$t[7])))) + ($fy*(($t[5] + ($fx*$t[8])) + ($fy*$t[9])))))); |
|
169 | 169 | } |
170 | - return ((float)$this->offset + ((float)$this->scale * (float)$h)); |
|
170 | + return ((float) $this->offset + ((float) $this->scale*(float) $h)); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | /* |
@@ -38,8 +38,11 @@ discard block |
||
38 | 38 | global $globalGeoidSource; |
39 | 39 | //if ($name == '') $name = dirname(__FILE__).'/../install/tmp/egm2008-1.pgm'; |
40 | 40 | if ($name == '') { |
41 | - if (isset($globalGeoidSource) && $globalGeoidSource != '') $name = dirname(__FILE__).'/../data/'.$globalGeoidSource.'.pgm'; |
|
42 | - else $name = dirname(__FILE__).'/../data/egm96-15.pgm'; |
|
41 | + if (isset($globalGeoidSource) && $globalGeoidSource != '') { |
|
42 | + $name = dirname(__FILE__).'/../data/'.$globalGeoidSource.'.pgm'; |
|
43 | + } else { |
|
44 | + $name = dirname(__FILE__).'/../data/egm96-15.pgm'; |
|
45 | + } |
|
43 | 46 | } |
44 | 47 | |
45 | 48 | if (file_exists($name) === FALSE) { |
@@ -159,7 +162,9 @@ discard block |
||
159 | 162 | } |
160 | 163 | } |
161 | 164 | $this->t = $t; |
162 | - } else $t = $this->t; |
|
165 | + } else { |
|
166 | + $t = $this->t; |
|
167 | + } |
|
163 | 168 | if (!($cubic)) { |
164 | 169 | $a = (((1 - $fx) * $this->v00) + ($fx * $this->v01)); |
165 | 170 | $b = (((1 - $fx) * $this->v10) + ($fx * $this->v11)); |