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