@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | default: |
42 | 42 | throw new \Exception("bad resolution can be only one of 1,3"); |
43 | 43 | } |
44 | - register_shutdown_function(function () { |
|
44 | + register_shutdown_function(function() { |
|
45 | 45 | $this->closeAllFiles(); |
46 | 46 | }); |
47 | 47 | } |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | |
56 | 56 | private function getElevationAtPosition($fileName, $row, $column) { |
57 | 57 | if (!array_key_exists($fileName, $this->openedFiles)) { |
58 | - if (!file_exists($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName)) { |
|
58 | + if (!file_exists($this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName)) { |
|
59 | 59 | throw new \Exception("File '{$fileName}' not exists."); |
60 | 60 | } |
61 | - $file = fopen($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName, "r"); |
|
61 | + $file = fopen($this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName, "r"); |
|
62 | 62 | if ($file === false) { |
63 | 63 | throw new \Exception("Cant open file '{$fileName}' for reading."); |
64 | 64 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | throw new \Exception("Not implemented yet"); |
73 | 73 | } |
74 | 74 | $aRow = $this->measPerDeg - $row; |
75 | - $position = ($this->measPerDeg * ($aRow - 1)) + $column; |
|
75 | + $position = ($this->measPerDeg*($aRow - 1)) + $column; |
|
76 | 76 | $position *= 2; |
77 | 77 | fseek($file, $position); |
78 | 78 | $short = fread($file, 2); |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | $latSec = $this->getSec($lat); |
111 | 111 | $lonSec = $this->getSec($lon); |
112 | 112 | |
113 | - $Xn = round($latSec / $this->resolution, 3); |
|
114 | - $Yn = round($lonSec / $this->resolution, 3); |
|
113 | + $Xn = round($latSec/$this->resolution, 3); |
|
114 | + $Yn = round($lonSec/$this->resolution, 3); |
|
115 | 115 | |
116 | 116 | $a1 = round($Xn); |
117 | 117 | $a2 = round($Yn); |
@@ -143,39 +143,39 @@ discard block |
||
143 | 143 | $b3 = $this->getElevationAtPosition($fName, $b1, $b2); |
144 | 144 | $c3 = $this->getElevationAtPosition($fName, $c1, $c2); |
145 | 145 | |
146 | - $n1 = ($c2 - $a2) * ($b3 - $a3) - ($c3 - $a3) * ($b2 - $a2); |
|
147 | - $n2 = ($c3 - $a3) * ($b1 - $a1) - ($c1 - $a1) * ($b3 - $a3); |
|
148 | - $n3 = ($c1 - $a1) * ($b2 - $a2) - ($c2 - $a2) * ($b1 - $a1); |
|
146 | + $n1 = ($c2 - $a2)*($b3 - $a3) - ($c3 - $a3)*($b2 - $a2); |
|
147 | + $n2 = ($c3 - $a3)*($b1 - $a1) - ($c1 - $a1)*($b3 - $a3); |
|
148 | + $n3 = ($c1 - $a1)*($b2 - $a2) - ($c2 - $a2)*($b1 - $a1); |
|
149 | 149 | |
150 | - $d = -$n1 * $a1 - $n2 * $a2 - $n3 * $a3; |
|
151 | - $zN = (-$n1 * $Xn - $n2 * $Yn - $d) / $n3; |
|
150 | + $d = -$n1*$a1 - $n2*$a2 - $n3*$a3; |
|
151 | + $zN = (-$n1*$Xn - $n2*$Yn - $d)/$n3; |
|
152 | 152 | if ($zN > 10000) return 0; |
153 | 153 | else return $zN; |
154 | 154 | } |
155 | 155 | |
156 | 156 | private function getDeg($deg, $numPrefix) { |
157 | 157 | $deg = abs($deg); |
158 | - $d = floor($deg); // round degrees |
|
158 | + $d = floor($deg); // round degrees |
|
159 | 159 | if ($numPrefix >= 3) { |
160 | 160 | if ($d < 100) { |
161 | - $d = '0' . $d; |
|
161 | + $d = '0'.$d; |
|
162 | 162 | } |
163 | 163 | } // pad with leading zeros |
164 | 164 | if ($d < 10) { |
165 | - $d = '0' . $d; |
|
165 | + $d = '0'.$d; |
|
166 | 166 | } |
167 | 167 | return $d; |
168 | 168 | } |
169 | 169 | |
170 | 170 | private function getSec($deg) { |
171 | 171 | $deg = abs($deg); |
172 | - $sec = round($deg * 3600, 4); |
|
173 | - $m = fmod(floor($sec / 60), 60); |
|
172 | + $sec = round($deg*3600, 4); |
|
173 | + $m = fmod(floor($sec/60), 60); |
|
174 | 174 | $s = round(fmod($sec, 60), 4); |
175 | - return ($m * 60) + $s; |
|
175 | + return ($m*60) + $s; |
|
176 | 176 | } |
177 | 177 | |
178 | - public function download($lat,$lon, $debug = false) { |
|
178 | + public function download($lat, $lon, $debug = false) { |
|
179 | 179 | if ($lat < 0) { |
180 | 180 | $latd = 'S'.$this->getDeg($lat, 2); |
181 | 181 | } else { |
@@ -186,20 +186,20 @@ discard block |
||
186 | 186 | } else { |
187 | 187 | $lond = 'W'.$this->getDeg($lon, 3); |
188 | 188 | } |
189 | - $fileName = $latd.$lond.".hgt"; |
|
190 | - if (!file_exists($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName)) { |
|
189 | + $fileName = $latd.$lond.".hgt"; |
|
190 | + if (!file_exists($this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName)) { |
|
191 | 191 | $Common = new Common(); |
192 | 192 | if ($debug) echo 'Downloading '.$fileName.'.gz ...'; |
193 | - $Common->download('https://s3.amazonaws.com/elevation-tiles-prod/skadi/'.$latd.'/'.$fileName.'.gz',$this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName . '.gz'); |
|
194 | - if (!file_exists($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName . '.gz')) { |
|
193 | + $Common->download('https://s3.amazonaws.com/elevation-tiles-prod/skadi/'.$latd.'/'.$fileName.'.gz', $this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName.'.gz'); |
|
194 | + if (!file_exists($this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName.'.gz')) { |
|
195 | 195 | if ($debug) echo "File '{$fileName}.gz' not exists."; |
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | if ($debug) echo 'Done'."\n"; |
199 | 199 | if ($debug) echo 'Decompress '.$fileName.' ....'; |
200 | - $Common->gunzip($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName . '.gz',$this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName); |
|
200 | + $Common->gunzip($this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName.'.gz', $this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName); |
|
201 | 201 | if ($debug) echo 'Done'."\n"; |
202 | - unlink($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName . '.gz'); |
|
202 | + unlink($this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName.'.gz'); |
|
203 | 203 | } |
204 | 204 | return true; |
205 | 205 | } |
@@ -212,22 +212,22 @@ discard block |
||
212 | 212 | try { |
213 | 213 | $sth = $db->prepare($query); |
214 | 214 | $sth->execute($query_values); |
215 | - } catch(PDOException $e) { |
|
215 | + } catch (PDOException $e) { |
|
216 | 216 | return "error : ".$e->getMessage(); |
217 | 217 | } |
218 | 218 | while ($data = $sth->fetch(PDO::FETCH_ASSOC)) { |
219 | - $this->download($data['latitude'],$data['longitude'],true); |
|
219 | + $this->download($data['latitude'], $data['longitude'], true); |
|
220 | 220 | } |
221 | 221 | $query = 'SELECT latitude, longitude FROM tracker_output WHERE latitude <> 0 AND longitude <> 0 ORDER BY date DESC LIMIT 10'; |
222 | 222 | $query_values = array(); |
223 | 223 | try { |
224 | 224 | $sth = $db->prepare($query); |
225 | 225 | $sth->execute($query_values); |
226 | - } catch(PDOException $e) { |
|
226 | + } catch (PDOException $e) { |
|
227 | 227 | return "error : ".$e->getMessage(); |
228 | 228 | } |
229 | 229 | while ($data = $sth->fetch(PDO::FETCH_ASSOC)) { |
230 | - $this->download($data['latitude'],$data['longitude'],true); |
|
230 | + $this->download($data['latitude'], $data['longitude'], true); |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | } |