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 \Runalyze\DEM\Interpolation\InterpolationInterface|null */ |
||
37 | protected $Interpolation; |
||
38 | |||
39 | /** @var \Runalyze\DEM\Provider\ResourceReaderInterface */ |
||
40 | protected $ResourceReader; |
||
41 | |||
42 | /** |
||
43 | * @param string $pathToFiles |
||
44 | * @param \Runalyze\DEM\Interpolation\InterpolationInterface|null $interpolation |
||
45 | */ |
||
46 | 8 | public function __construct($pathToFiles, InterpolationInterface $interpolation = null) |
|
53 | |||
54 | /** |
||
55 | * @param \Runalyze\DEM\Interpolation\InterpolationInterface $interpolation |
||
56 | */ |
||
57 | 8 | public function setInterpolation(InterpolationInterface $interpolation) |
|
61 | |||
62 | /** |
||
63 | * @param array $latitudeLongitudes array(array($lat, $lng), ...) |
||
64 | * @return bool |
||
65 | */ |
||
66 | 2 | public function hasDataFor(array $latitudeLongitudes) |
|
84 | |||
85 | /** |
||
86 | * @param float $latitude |
||
87 | * @param float $longitude |
||
88 | * @return bool |
||
89 | */ |
||
90 | 8 | protected function locationIsInBounds($latitude, $longitude) |
|
97 | |||
98 | /** |
||
99 | * @return bool |
||
100 | */ |
||
101 | 6 | public function usesInterpolation() |
|
105 | |||
106 | /** |
||
107 | * @param float[] $latitudes |
||
108 | * @param float[] $longitudes |
||
109 | * @throws \InvalidArgumentException |
||
110 | * @return array elevations [m] can be false if nothing retrieved |
||
111 | */ |
||
112 | 4 | public function getElevations(array $latitudes, array $longitudes) |
|
127 | |||
128 | /** |
||
129 | * Get elevation for specified location. |
||
130 | * |
||
131 | * Availability of data must be checked in advance via hasDataFor($locations). |
||
132 | * |
||
133 | * @param float $latitude |
||
134 | * @param float $longitude |
||
135 | * @return int|bool elevation [m] can be false if nothing retrieved |
||
136 | */ |
||
137 | 6 | public function getElevation($latitude, $longitude) |
|
157 | |||
158 | /** |
||
159 | * @param float $latitude |
||
160 | * @param float $longitude |
||
161 | * @return int|bool can be false if nothing retrieved |
||
162 | */ |
||
163 | 6 | protected function getElevationFromResource($latitude, $longitude) |
|
173 | |||
174 | /** |
||
175 | * @param float $exactRowValue |
||
176 | * @param float $exactColValue |
||
177 | * @return int|bool can be false if nothing retrieved |
||
178 | */ |
||
179 | 6 | protected function getInterpolatedElevationFor($exactRowValue, $exactColValue) |
|
199 | |||
200 | /** |
||
201 | * @param string $filename |
||
202 | * @return bool |
||
203 | */ |
||
204 | protected function resourceIsCurrentlyOpened($filename) |
||
208 | |||
209 | /** |
||
210 | * @param float $latitude |
||
211 | * @param float $longitude |
||
212 | * @return string |
||
213 | */ |
||
214 | abstract protected function getFilenameFor($latitude, $longitude); |
||
215 | |||
216 | abstract protected function initResourceReader(); |
||
217 | |||
218 | /** |
||
219 | * @param string $filename |
||
220 | */ |
||
221 | abstract protected function openResource($filename); |
||
222 | |||
223 | /** |
||
224 | * @param int $row |
||
225 | * @param int $col |
||
226 | * @return int|bool elevation [m] can be false if nothing retrieved |
||
227 | */ |
||
228 | abstract protected function getElevationFor($row, $col); |
||
229 | |||
230 | /** |
||
231 | * @param float $latitude |
||
232 | * @param float $longitude |
||
233 | * @return array array(row, col) |
||
234 | */ |
||
235 | abstract protected function getExactRowAndColFor($latitude, $longitude); |
||
236 | } |
||
237 |