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