@@ -53,6 +53,11 @@ discard block |
||
53 | 53 | $this->openedFiles = []; |
54 | 54 | } |
55 | 55 | |
56 | + /** |
|
57 | + * @param string $fileName |
|
58 | + * @param double $row |
|
59 | + * @param double $column |
|
60 | + */ |
|
56 | 61 | private function getElevationAtPosition($fileName, $row, $column) { |
57 | 62 | if (!array_key_exists($fileName, $this->openedFiles)) { |
58 | 63 | if (!file_exists($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName)) { |
@@ -153,6 +158,9 @@ discard block |
||
153 | 158 | else return $zN; |
154 | 159 | } |
155 | 160 | |
161 | + /** |
|
162 | + * @param integer $numPrefix |
|
163 | + */ |
|
156 | 164 | private function getDeg($deg, $numPrefix) { |
157 | 165 | $deg = abs($deg); |
158 | 166 | $d = floor($deg); // round degrees |
@@ -167,6 +175,9 @@ discard block |
||
167 | 175 | return $d; |
168 | 176 | } |
169 | 177 | |
178 | + /** |
|
179 | + * @param double $deg |
|
180 | + */ |
|
170 | 181 | private function getSec($deg) { |
171 | 182 | $deg = abs($deg); |
172 | 183 | $sec = round($deg * 3600, 4); |
@@ -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 | } |
@@ -28,7 +28,9 @@ discard block |
||
28 | 28 | private $openedFiles = []; |
29 | 29 | |
30 | 30 | public function __construct($htgFilesDestination = '', $resolution = 3) { |
31 | - if ($htgFilesDestination == '') $htgFilesDestination = dirname(__FILE__).'/../data/'; |
|
31 | + if ($htgFilesDestination == '') { |
|
32 | + $htgFilesDestination = dirname(__FILE__).'/../data/'; |
|
33 | + } |
|
32 | 34 | $this->htgFilesDestination = $htgFilesDestination; |
33 | 35 | $this->resolution = $resolution; |
34 | 36 | switch ($resolution) { |
@@ -149,8 +151,11 @@ discard block |
||
149 | 151 | |
150 | 152 | $d = -$n1 * $a1 - $n2 * $a2 - $n3 * $a3; |
151 | 153 | $zN = (-$n1 * $Xn - $n2 * $Yn - $d) / $n3; |
152 | - if ($zN > 10000) return 0; |
|
153 | - else return $zN; |
|
154 | + if ($zN > 10000) { |
|
155 | + return 0; |
|
156 | + } else { |
|
157 | + return $zN; |
|
158 | + } |
|
154 | 159 | } |
155 | 160 | |
156 | 161 | private function getDeg($deg, $numPrefix) { |
@@ -189,16 +194,26 @@ discard block |
||
189 | 194 | $fileName = $latd.$lond.".hgt"; |
190 | 195 | if (!file_exists($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName)) { |
191 | 196 | $Common = new Common(); |
192 | - if ($debug) echo 'Downloading '.$fileName.'.gz ...'; |
|
197 | + if ($debug) { |
|
198 | + echo 'Downloading '.$fileName.'.gz ...'; |
|
199 | + } |
|
193 | 200 | $Common->download('https://s3.amazonaws.com/elevation-tiles-prod/skadi/'.$latd.'/'.$fileName.'.gz',$this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName . '.gz'); |
194 | 201 | if (!file_exists($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName . '.gz')) { |
195 | - if ($debug) echo "File '{$fileName}.gz' not exists."; |
|
202 | + if ($debug) { |
|
203 | + echo "File '{$fileName}.gz' not exists."; |
|
204 | + } |
|
196 | 205 | return false; |
197 | 206 | } |
198 | - if ($debug) echo 'Done'."\n"; |
|
199 | - if ($debug) echo 'Decompress '.$fileName.' ....'; |
|
207 | + if ($debug) { |
|
208 | + echo 'Done'."\n"; |
|
209 | + } |
|
210 | + if ($debug) { |
|
211 | + echo 'Decompress '.$fileName.' ....'; |
|
212 | + } |
|
200 | 213 | $Common->gunzip($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName . '.gz',$this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName); |
201 | - if ($debug) echo 'Done'."\n"; |
|
214 | + if ($debug) { |
|
215 | + echo 'Done'."\n"; |
|
216 | + } |
|
202 | 217 | unlink($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName . '.gz'); |
203 | 218 | } |
204 | 219 | return true; |