1 | <?php |
||
17 | abstract class AbstractFileProvider implements ProviderInterface |
||
18 | { |
||
19 | use GuessInvalidValuesTrait; |
||
20 | |||
21 | /** @var int */ |
||
22 | const MAX_LATITUDE = 90; |
||
23 | |||
24 | /** @var int */ |
||
25 | const MAX_LONGITUDE = 180; |
||
26 | |||
27 | /** @var string */ |
||
28 | protected $PathToFiles; |
||
29 | |||
30 | /** @var resource */ |
||
31 | protected $FileResource; |
||
32 | |||
33 | /** @var string|bool */ |
||
34 | protected $CurrentFilename = false; |
||
35 | |||
36 | /** @var InterpolationInterface|null */ |
||
37 | protected $Interpolation; |
||
38 | |||
39 | /** @var ResourceReaderInterface */ |
||
40 | protected $ResourceReader; |
||
41 | |||
42 | /** |
||
43 | * @param string $pathToFiles |
||
44 | * @param InterpolationInterface|null $interpolation |
||
45 | */ |
||
46 | 19 | public function __construct($pathToFiles, InterpolationInterface $interpolation = null) |
|
47 | 2 | { |
|
48 | 19 | $this->PathToFiles = $pathToFiles; |
|
49 | 19 | $this->Interpolation = $interpolation; |
|
50 | |||
51 | 19 | $this->initResourceReader(); |
|
52 | 19 | } |
|
53 | |||
54 | /** |
||
55 | * @param InterpolationInterface $interpolation |
||
56 | */ |
||
57 | 13 | public function setInterpolation(InterpolationInterface $interpolation) |
|
61 | |||
62 | 1 | public function removeInterpolation() |
|
66 | |||
67 | /** |
||
68 | * @param array $latitudeLongitudes array(array($lat, $lng), ...) |
||
69 | * @return bool |
||
70 | * @throws InvalidArgumentException |
||
71 | */ |
||
72 | 8 | public function hasDataFor(array $latitudeLongitudes) |
|
90 | |||
91 | /** |
||
92 | * @param float $latitude |
||
93 | * @param float $longitude |
||
94 | * @return bool |
||
95 | */ |
||
96 | 14 | protected function locationIsInBounds($latitude, $longitude) |
|
103 | |||
104 | /** |
||
105 | * @return bool |
||
106 | */ |
||
107 | 7 | public function usesInterpolation() |
|
111 | |||
112 | /** |
||
113 | * @param float[] $latitudes |
||
114 | * @param float[] $longitudes |
||
115 | * @return array elevations [m] can be false if nothing retrieved |
||
116 | * @throws InvalidArgumentException; |
||
117 | */ |
||
118 | 6 | public function getElevations(array $latitudes, array $longitudes) |
|
133 | |||
134 | /** |
||
135 | * Get elevation for specified location. |
||
136 | * |
||
137 | * Availability of data must be checked in advance via hasDataFor($locations). |
||
138 | * Only 'invalid' locations such as (0.0, 0.0) won't throw an exception but return false. |
||
139 | * |
||
140 | * @param float $latitude |
||
141 | * @param float $longitude |
||
142 | * @return int|bool elevation [m] can be false if nothing retrieved |
||
143 | * @throws InvalidArgumentException; |
||
144 | */ |
||
145 | 10 | public function getElevation($latitude, $longitude) |
|
169 | |||
170 | /** |
||
171 | * @param float $latitude |
||
172 | * @param float $longitude |
||
173 | * @return int|bool can be false if nothing retrieved |
||
174 | */ |
||
175 | 7 | protected function getElevationFromResource($latitude, $longitude) |
|
185 | |||
186 | /** |
||
187 | * @param float $exactRowValue |
||
188 | * @param float $exactColValue |
||
189 | * @return int|bool can be false if nothing retrieved |
||
190 | */ |
||
191 | 6 | protected function getInterpolatedElevationFor($exactRowValue, $exactColValue) |
|
211 | |||
212 | /** |
||
213 | * @param float $latitude |
||
214 | * @param float $longitude |
||
215 | * @return string |
||
216 | */ |
||
217 | abstract protected function getFilenameFor($latitude, $longitude); |
||
218 | |||
219 | abstract protected function initResourceReader(); |
||
220 | |||
221 | /** |
||
222 | * @param string $filename |
||
223 | */ |
||
224 | abstract protected function openResource($filename); |
||
225 | |||
226 | /** |
||
227 | * @param int $row |
||
228 | * @param int $col |
||
229 | * @return int|bool elevation [m] can be false if nothing retrieved |
||
230 | */ |
||
231 | abstract protected function getElevationFor($row, $col); |
||
232 | |||
233 | /** |
||
234 | * @param float $latitude |
||
235 | * @param float $longitude |
||
236 | * @return array array(row, col) |
||
237 | */ |
||
238 | abstract protected function getExactRowAndColFor($latitude, $longitude); |
||
239 | } |
||
240 |