1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PHPCoord. |
5
|
|
|
* |
6
|
|
|
* @author Doug Wright |
7
|
|
|
*/ |
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace PHPCoord\CoordinateOperation; |
11
|
|
|
|
12
|
|
|
use Composer\Pcre\Preg; |
13
|
|
|
use PHPCoord\UnitOfMeasure\Length\Metre; |
14
|
|
|
use SplFixedArray; |
15
|
|
|
|
16
|
|
|
use function explode; |
17
|
|
|
use function trim; |
18
|
|
|
use function assert; |
19
|
|
|
|
20
|
|
|
class OSGM15IrelandGrid extends GeographicGeoidHeightGrid |
21
|
|
|
{ |
22
|
|
|
use BilinearInterpolation; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var SplFixedArray<float> |
26
|
|
|
*/ |
27
|
|
|
private SplFixedArray $textData; |
28
|
|
|
|
29
|
|
|
public function __construct(string $filename) |
30
|
|
|
{ |
31
|
|
|
$this->gridFile = new GridFile($filename); |
32
|
|
|
$this->storageOrder = self::STORAGE_ORDER_INCREASING_LONGITUDE_DECREASING_LATIITUDE; |
33
|
|
|
|
34
|
|
|
$header = Preg::split('/\s+/', trim($this->gridFile->fgets())); |
35
|
|
|
|
36
|
|
|
$this->startX = (float) $header[2]; |
37
|
|
|
$this->startY = (float) $header[0]; |
38
|
|
|
$this->endX = (float) $header[3]; |
39
|
|
|
$this->endY = (float) $header[1]; |
40
|
|
|
$this->columnGridInterval = (float) $header[5]; |
41
|
|
|
$this->rowGridInterval = (float) $header[4]; |
42
|
|
|
$this->numberOfColumns = (int) (string) (($this->endX - $this->startX) / $this->columnGridInterval) + 1; |
43
|
|
|
$this->numberOfRows = (int) (string) (($this->endY - $this->startY) / $this->rowGridInterval) + 1; |
44
|
|
|
|
45
|
|
|
$this->textData = new SplFixedArray($this->numberOfColumns * $this->numberOfRows); |
46
|
|
|
$index = 0; |
47
|
|
|
while (!$this->gridFile->eof()) { |
48
|
|
|
$rawData = trim($this->gridFile->fgets()); |
49
|
|
|
if ($rawData) { |
50
|
|
|
$values = explode(' ', trim(Preg::replace('/\s+/', ' ', $rawData))); |
51
|
|
|
foreach ($values as $value) { |
52
|
|
|
$this->textData[$index] = (float) $value; |
53
|
|
|
++$index; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return Metre[] |
61
|
|
|
*/ |
62
|
|
|
public function getValues(float $x, float $y): array |
63
|
|
|
{ |
64
|
|
|
$shift = $this->interpolate($x, $y)[0]; |
65
|
|
|
|
66
|
|
|
return [new Metre($shift)]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
private function getRecord(int $longitudeIndex, int $latitudeIndex): GridValues |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$recordId = ($this->numberOfRows - $latitudeIndex - 1) * $this->numberOfColumns + $longitudeIndex; |
72
|
|
|
$longitude = $longitudeIndex * $this->columnGridInterval + $this->startX; |
73
|
|
|
$latitude = $latitudeIndex * $this->rowGridInterval + $this->startY; |
74
|
|
|
|
75
|
|
|
assert($this->textData[$recordId] !== null); |
76
|
|
|
|
77
|
|
|
return new GridValues( |
78
|
|
|
$longitude, |
79
|
|
|
$latitude, |
80
|
|
|
[$this->textData[$recordId]] |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This check looks for private methods that have been defined, but are not used inside the class.