1 | <?php |
||
18 | abstract class AbstractFileProvider implements ProviderInterface |
||
19 | { |
||
20 | use GuessInvalidValuesTrait; |
||
21 | |||
22 | /** @var int */ |
||
23 | const MAX_LATITUDE = 90; |
||
24 | |||
25 | /** @var int */ |
||
26 | const MAX_LONGITUDE = 180; |
||
27 | |||
28 | /** @var string */ |
||
29 | protected $PathToFiles; |
||
30 | |||
31 | /** @var resource */ |
||
32 | protected $FileResource; |
||
33 | |||
34 | /** @var string|bool */ |
||
35 | protected $CurrentFilename = false; |
||
36 | |||
37 | /** @var InterpolationInterface|null */ |
||
38 | protected $Interpolation; |
||
39 | |||
40 | /** @var ResourceReaderInterface */ |
||
41 | protected $ResourceReader; |
||
42 | |||
43 | /** |
||
44 | * @param string $pathToFiles |
||
45 | * @param InterpolationInterface|null $interpolation |
||
46 | */ |
||
47 | 9 | public function __construct($pathToFiles, InterpolationInterface $interpolation = null) |
|
54 | |||
55 | /** |
||
56 | * @param InterpolationInterface $interpolation |
||
57 | */ |
||
58 | 9 | public function setInterpolation(InterpolationInterface $interpolation) |
|
62 | |||
63 | /** |
||
64 | * @param array $latitudeLongitudes array(array($lat, $lng), ...) |
||
65 | * @return bool |
||
66 | * @throws InvalidArgumentException |
||
67 | */ |
||
68 | 2 | public function hasDataFor(array $latitudeLongitudes) |
|
86 | |||
87 | /** |
||
88 | * @param float $latitude |
||
89 | * @param float $longitude |
||
90 | * @return bool |
||
91 | */ |
||
92 | 8 | protected function locationIsInBounds($latitude, $longitude) |
|
99 | |||
100 | /** |
||
101 | * @return bool |
||
102 | */ |
||
103 | 6 | public function usesInterpolation() |
|
107 | |||
108 | /** |
||
109 | * @param float[] $latitudes |
||
110 | * @param float[] $longitudes |
||
111 | * @return array elevations [m] can be false if nothing retrieved |
||
112 | * @throws InvalidArgumentException; |
||
113 | */ |
||
114 | 4 | public function getElevations(array $latitudes, array $longitudes) |
|
129 | |||
130 | /** |
||
131 | * Get elevation for specified location. |
||
132 | * |
||
133 | * Availability of data must be checked in advance via hasDataFor($locations). |
||
134 | * Only 'invalid' locations such as (0.0, 0.0) won't throw an exception but return false. |
||
135 | * |
||
136 | * @param float $latitude |
||
137 | * @param float $longitude |
||
138 | * @return int|bool elevation [m] can be false if nothing retrieved |
||
139 | * @throws InvalidArgumentException; |
||
140 | */ |
||
141 | 7 | public function getElevation($latitude, $longitude) |
|
165 | |||
166 | /** |
||
167 | * @param float $latitude |
||
168 | * @param float $longitude |
||
169 | * @return int|bool can be false if nothing retrieved |
||
170 | */ |
||
171 | 6 | protected function getElevationFromResource($latitude, $longitude) |
|
181 | |||
182 | /** |
||
183 | * @param float $exactRowValue |
||
184 | * @param float $exactColValue |
||
185 | * @return int|bool can be false if nothing retrieved |
||
186 | */ |
||
187 | 6 | protected function getInterpolatedElevationFor($exactRowValue, $exactColValue) |
|
207 | |||
208 | /** |
||
209 | * @param string $filename |
||
210 | * @return bool |
||
211 | */ |
||
212 | protected function resourceIsCurrentlyOpened($filename) |
||
216 | |||
217 | /** |
||
218 | * @param float $latitude |
||
219 | * @param float $longitude |
||
220 | * @return string |
||
221 | */ |
||
222 | abstract protected function getFilenameFor($latitude, $longitude); |
||
223 | |||
224 | abstract protected function initResourceReader(); |
||
225 | |||
226 | /** |
||
227 | * @param string $filename |
||
228 | */ |
||
229 | abstract protected function openResource($filename); |
||
230 | |||
231 | /** |
||
232 | * @param int $row |
||
233 | * @param int $col |
||
234 | * @return int|bool elevation [m] can be false if nothing retrieved |
||
235 | */ |
||
236 | abstract protected function getElevationFor($row, $col); |
||
237 | |||
238 | /** |
||
239 | * @param float $latitude |
||
240 | * @param float $longitude |
||
241 | * @return array array(row, col) |
||
242 | */ |
||
243 | abstract protected function getExactRowAndColFor($latitude, $longitude); |
||
244 | } |
||
245 |