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
|
1 |
|
public function __construct($filename) |
27
|
|
|
{ |
28
|
1 |
|
$this->gridFile = new SplFileObject($filename); |
29
|
1 |
|
$this->storageOrder = self::STORAGE_ORDER_INCREASING_LONGITUDE_DECREASING_LATIITUDE; |
30
|
|
|
|
31
|
1 |
|
$header = preg_split('/\s+/', trim($this->gridFile->fgets())); |
32
|
|
|
|
33
|
1 |
|
$this->startX = (float) $header[2]; |
34
|
1 |
|
$this->startY = (float) $header[0]; |
35
|
1 |
|
$this->endX = (float) $header[3]; |
36
|
1 |
|
$this->endY = (float) $header[1]; |
37
|
1 |
|
$this->columnGridInterval = (float) $header[5]; |
38
|
1 |
|
$this->rowGridInterval = (float) $header[4]; |
39
|
1 |
|
$this->numberOfColumns = (int) (string) (($this->endX - $this->startX) / $this->columnGridInterval) + 1; |
40
|
1 |
|
$this->numberOfRows = (int) (string) (($this->endY - $this->startY) / $this->rowGridInterval) + 1; |
41
|
|
|
|
42
|
1 |
|
$this->textData = new SplFixedArray($this->numberOfColumns * $this->numberOfRows); |
43
|
1 |
|
$index = 0; |
44
|
1 |
|
while (!$this->gridFile->eof()) { |
45
|
1 |
|
$rawData = trim($this->gridFile->fgets()); |
46
|
1 |
|
if ($rawData) { |
47
|
1 |
|
$values = explode(' ', trim(preg_replace('/\s+/', ' ', $rawData))); |
48
|
1 |
|
foreach ($values as $value) { |
49
|
1 |
|
$this->textData[$index] = (float) $value; |
50
|
1 |
|
++$index; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return Metre[] |
58
|
|
|
*/ |
59
|
1 |
|
public function getValues($x, $y): array |
60
|
|
|
{ |
61
|
1 |
|
$shift = $this->interpolate($x, $y)[0]; |
62
|
|
|
|
63
|
1 |
|
return [new Metre($shift)]; |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
private function getRecord(int $longitudeIndex, int $latitudeIndex): GridValues |
|
|
|
|
67
|
|
|
{ |
68
|
1 |
|
$recordId = ($this->numberOfRows - $latitudeIndex - 1) * $this->numberOfColumns + $longitudeIndex; |
69
|
1 |
|
$longitude = $longitudeIndex * $this->columnGridInterval + $this->startX; |
70
|
1 |
|
$latitude = $latitudeIndex * $this->rowGridInterval + $this->startY; |
71
|
|
|
|
72
|
1 |
|
return new GridValues( |
73
|
1 |
|
$longitude, |
74
|
1 |
|
$latitude, |
75
|
1 |
|
[$this->textData[$recordId]] |
76
|
1 |
|
); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This check looks for private methods that have been defined, but are not used inside the class.