@@ -52,6 +52,10 @@ discard block |
||
| 52 | 52 | $this->openedFiles = []; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | + /** |
|
| 56 | + * @param double $row |
|
| 57 | + * @param double $column |
|
| 58 | + */ |
|
| 55 | 59 | private function getElevationAtPosition($fileName, $row, $column) { |
| 56 | 60 | if (!array_key_exists($fileName, $this->openedFiles)) { |
| 57 | 61 | if (!file_exists($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName)) { |
@@ -85,7 +89,7 @@ discard block |
||
| 85 | 89 | * @param float $lon |
| 86 | 90 | * @param null $fName |
| 87 | 91 | * |
| 88 | - * @return mixed |
|
| 92 | + * @return double |
|
| 89 | 93 | * @throws \Exception |
| 90 | 94 | */ |
| 91 | 95 | public function getElevation($lat, $lon, &$fName = null) { |
@@ -142,6 +146,9 @@ discard block |
||
| 142 | 146 | return $zN; |
| 143 | 147 | } |
| 144 | 148 | |
| 149 | + /** |
|
| 150 | + * @param integer $numPrefix |
|
| 151 | + */ |
|
| 145 | 152 | private function getDeg($deg, $numPrefix) { |
| 146 | 153 | $deg = abs($deg); |
| 147 | 154 | $d = floor($deg); // round degrees |
@@ -156,6 +163,9 @@ discard block |
||
| 156 | 163 | return $d; |
| 157 | 164 | } |
| 158 | 165 | |
| 166 | + /** |
|
| 167 | + * @param double $deg |
|
| 168 | + */ |
|
| 159 | 169 | private function getSec($deg) { |
| 160 | 170 | $deg = abs($deg); |
| 161 | 171 | $sec = round($deg * 3600, 4); |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | default: |
| 41 | 41 | throw new \Exception("bad resolution can be only one of 1,3"); |
| 42 | 42 | } |
| 43 | - register_shutdown_function(function () { |
|
| 43 | + register_shutdown_function(function() { |
|
| 44 | 44 | $this->closeAllFiles(); |
| 45 | 45 | }); |
| 46 | 46 | } |
@@ -54,10 +54,10 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | private function getElevationAtPosition($fileName, $row, $column) { |
| 56 | 56 | if (!array_key_exists($fileName, $this->openedFiles)) { |
| 57 | - if (!file_exists($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName)) { |
|
| 57 | + if (!file_exists($this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName)) { |
|
| 58 | 58 | throw new \Exception("File '{$fileName}' not exists."); |
| 59 | 59 | } |
| 60 | - $file = fopen($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName, "r"); |
|
| 60 | + $file = fopen($this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName, "r"); |
|
| 61 | 61 | if ($file === false) { |
| 62 | 62 | throw new \Exception("Cant open file '{$fileName}' for reading."); |
| 63 | 63 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | throw new \Exception("Mot implemented yet"); |
| 72 | 72 | } |
| 73 | 73 | $aRow = $this->measPerDeg - $row; |
| 74 | - $position = ($this->measPerDeg * ($aRow - 1)) + $column; |
|
| 74 | + $position = ($this->measPerDeg*($aRow - 1)) + $column; |
|
| 75 | 75 | $position *= 2; |
| 76 | 76 | fseek($file, $position); |
| 77 | 77 | $short = fread($file, 2); |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | $latSec = $this->getSec($lat); |
| 100 | 100 | $lonSec = $this->getSec($lon); |
| 101 | 101 | |
| 102 | - $Xn = round($latSec / $this->resolution, 3); |
|
| 103 | - $Yn = round($lonSec / $this->resolution, 3); |
|
| 102 | + $Xn = round($latSec/$this->resolution, 3); |
|
| 103 | + $Yn = round($lonSec/$this->resolution, 3); |
|
| 104 | 104 | |
| 105 | 105 | $a1 = round($Xn); |
| 106 | 106 | $a2 = round($Yn); |
@@ -132,50 +132,50 @@ discard block |
||
| 132 | 132 | $b3 = $this->getElevationAtPosition($fName, $b1, $b2); |
| 133 | 133 | $c3 = $this->getElevationAtPosition($fName, $c1, $c2); |
| 134 | 134 | |
| 135 | - $n1 = ($c2 - $a2) * ($b3 - $a3) - ($c3 - $a3) * ($b2 - $a2); |
|
| 136 | - $n2 = ($c3 - $a3) * ($b1 - $a1) - ($c1 - $a1) * ($b3 - $a3); |
|
| 137 | - $n3 = ($c1 - $a1) * ($b2 - $a2) - ($c2 - $a2) * ($b1 - $a1); |
|
| 135 | + $n1 = ($c2 - $a2)*($b3 - $a3) - ($c3 - $a3)*($b2 - $a2); |
|
| 136 | + $n2 = ($c3 - $a3)*($b1 - $a1) - ($c1 - $a1)*($b3 - $a3); |
|
| 137 | + $n3 = ($c1 - $a1)*($b2 - $a2) - ($c2 - $a2)*($b1 - $a1); |
|
| 138 | 138 | |
| 139 | - $d = -$n1 * $a1 - $n2 * $a2 - $n3 * $a3; |
|
| 140 | - $zN = (-$n1 * $Xn - $n2 * $Yn - $d) / $n3; |
|
| 139 | + $d = -$n1*$a1 - $n2*$a2 - $n3*$a3; |
|
| 140 | + $zN = (-$n1*$Xn - $n2*$Yn - $d)/$n3; |
|
| 141 | 141 | |
| 142 | 142 | return $zN; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | private function getDeg($deg, $numPrefix) { |
| 146 | 146 | $deg = abs($deg); |
| 147 | - $d = floor($deg); // round degrees |
|
| 147 | + $d = floor($deg); // round degrees |
|
| 148 | 148 | if ($numPrefix >= 3) { |
| 149 | 149 | if ($d < 100) { |
| 150 | - $d = '0' . $d; |
|
| 150 | + $d = '0'.$d; |
|
| 151 | 151 | } |
| 152 | 152 | } // pad with leading zeros |
| 153 | 153 | if ($d < 10) { |
| 154 | - $d = '0' . $d; |
|
| 154 | + $d = '0'.$d; |
|
| 155 | 155 | } |
| 156 | 156 | return $d; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | private function getSec($deg) { |
| 160 | 160 | $deg = abs($deg); |
| 161 | - $sec = round($deg * 3600, 4); |
|
| 162 | - $m = fmod(floor($sec / 60), 60); |
|
| 161 | + $sec = round($deg*3600, 4); |
|
| 162 | + $m = fmod(floor($sec/60), 60); |
|
| 163 | 163 | $s = round(fmod($sec, 60), 4); |
| 164 | - return ($m * 60) + $s; |
|
| 164 | + return ($m*60) + $s; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - public function download($lat,$lon) { |
|
| 167 | + public function download($lat, $lon) { |
|
| 168 | 168 | $N = $this->getDeg($lat, 2); |
| 169 | 169 | $E = $this->getDeg($lon, 3); |
| 170 | - $fileName = "N{$N}E{$E}.hgt"; |
|
| 171 | - if (!file_exists($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName)) { |
|
| 170 | + $fileName = "N{$N}E{$E}.hgt"; |
|
| 171 | + if (!file_exists($this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName)) { |
|
| 172 | 172 | $Common = new Common(); |
| 173 | - $Common->download('https://s3.amazonaws.com/elevation-tiles-prod/skadi/N'.$N.'/'.$fileName.'.gz',$this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName . '.gz'); |
|
| 174 | - if (!file_exists($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName . '.gz')) { |
|
| 173 | + $Common->download('https://s3.amazonaws.com/elevation-tiles-prod/skadi/N'.$N.'/'.$fileName.'.gz', $this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName.'.gz'); |
|
| 174 | + if (!file_exists($this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName.'.gz')) { |
|
| 175 | 175 | throw new \Exception("File '{$fileName}.gz' not exists."); |
| 176 | 176 | } |
| 177 | - $Common->gunzip($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName . '.gz',$this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName); |
|
| 178 | - unlink($this->htgFilesDestination . DIRECTORY_SEPARATOR . $fileName . '.gz'); |
|
| 177 | + $Common->gunzip($this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName.'.gz', $this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName); |
|
| 178 | + unlink($this->htgFilesDestination.DIRECTORY_SEPARATOR.$fileName.'.gz'); |
|
| 179 | 179 | } |
| 180 | 180 | return true; |
| 181 | 181 | } |
@@ -27,7 +27,9 @@ |
||
| 27 | 27 | private $openedFiles = []; |
| 28 | 28 | |
| 29 | 29 | public function __construct($htgFilesDestination = '', $resolution = 3) { |
| 30 | - if ($htgFilesDestination == '') $htgFilesDestination = dirname(__FILE__).'/../install/tmp/'; |
|
| 30 | + if ($htgFilesDestination == '') { |
|
| 31 | + $htgFilesDestination = dirname(__FILE__).'/../install/tmp/'; |
|
| 32 | + } |
|
| 31 | 33 | $this->htgFilesDestination = $htgFilesDestination; |
| 32 | 34 | $this->resolution = $resolution; |
| 33 | 35 | switch ($resolution) { |