|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHPCoord. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Doug Wright |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace PHPCoord\CoordinateOperation; |
|
10
|
|
|
|
|
11
|
|
|
use function abs; |
|
12
|
|
|
use const PHP_MAJOR_VERSION; |
|
13
|
|
|
use PHPCoord\CoordinateReferenceSystem\Projected; |
|
|
|
|
|
|
14
|
|
|
use PHPCoord\CoordinateSystem\Cartesian; |
|
15
|
|
|
use PHPCoord\Datum\Datum; |
|
16
|
|
|
use PHPCoord\ProjectedPoint; |
|
17
|
|
|
use PHPCoord\UnitOfMeasure\Length\Metre; |
|
18
|
|
|
use SplFileObject; |
|
19
|
|
|
|
|
20
|
|
|
class OSTNOSGM15Grid extends SplFileObject |
|
21
|
|
|
{ |
|
22
|
|
|
use BilinearInterpolation; |
|
23
|
|
|
|
|
24
|
|
|
private const ITERATION_CONVERGENCE = 0.0001; |
|
25
|
|
|
|
|
26
|
11 |
|
public function __construct($filename) |
|
27
|
|
|
{ |
|
28
|
11 |
|
parent::__construct($filename); |
|
29
|
|
|
|
|
30
|
11 |
|
$this->startX = 0; |
|
31
|
11 |
|
$this->startY = 0; |
|
32
|
11 |
|
$this->columnGridInterval = 1000; |
|
33
|
11 |
|
$this->rowGridInterval = 1000; |
|
34
|
11 |
|
$this->numberOfColumns = 700; |
|
35
|
11 |
|
$this->numberOfRows = 1250; |
|
36
|
11 |
|
} |
|
37
|
|
|
|
|
38
|
2 |
|
public function applyForwardHorizontalAdjustment(ProjectedPoint $point): ProjectedPoint |
|
39
|
|
|
{ |
|
40
|
2 |
|
$adjustment = $this->getAdjustment($point->getEasting()->asMetres(), $point->getNorthing()->asMetres()); |
|
41
|
|
|
|
|
42
|
2 |
|
$easting = $point->getEasting()->add(new Metre($adjustment[0])); |
|
43
|
2 |
|
$northing = $point->getNorthing()->add(new Metre($adjustment[1])); |
|
44
|
|
|
|
|
45
|
2 |
|
return ProjectedPoint::createFromEastingNorthing($easting, $northing, Projected::fromSRID(Projected::EPSG_OSGB36_BRITISH_NATIONAL_GRID), $point->getCoordinateEpoch()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
6 |
|
public function applyReverseHorizontalAdjustment(ProjectedPoint $point): ProjectedPoint |
|
49
|
|
|
{ |
|
50
|
6 |
|
$osgb36NationalGrid = Projected::fromSRID(Projected::EPSG_OSGB36_BRITISH_NATIONAL_GRID); |
|
51
|
6 |
|
$etrs89NationalGrid = new Projected( |
|
52
|
6 |
|
'ETRS89 / National Grid', |
|
53
|
6 |
|
Cartesian::fromSRID(Cartesian::EPSG_2D_AXES_EASTING_NORTHING_E_N_ORIENTATIONS_EAST_NORTH_UOM_M), |
|
54
|
6 |
|
Datum::fromSRID(Datum::EPSG_EUROPEAN_TERRESTRIAL_REFERENCE_SYSTEM_1989_ENSEMBLE), |
|
55
|
6 |
|
$osgb36NationalGrid->getBoundingArea() |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
6 |
|
$adjustment = [0, 0]; |
|
59
|
6 |
|
$easting = $point->getEasting(); |
|
60
|
6 |
|
$northing = $point->getNorthing(); |
|
61
|
|
|
|
|
62
|
|
|
do { |
|
63
|
6 |
|
$prevAdjustment = $adjustment; |
|
64
|
6 |
|
$adjustment = $this->getAdjustment($easting->asMetres(), $northing->asMetres()); |
|
65
|
6 |
|
$easting = $point->getEasting()->subtract(new Metre($adjustment[0])); |
|
66
|
6 |
|
$northing = $point->getNorthing()->subtract(new Metre($adjustment[1])); |
|
67
|
6 |
|
} while (abs($adjustment[0] - $prevAdjustment[0]) > self::ITERATION_CONVERGENCE && abs($adjustment[1] - $prevAdjustment[1]) > self::ITERATION_CONVERGENCE); |
|
68
|
|
|
|
|
69
|
6 |
|
return ProjectedPoint::createFromEastingNorthing($easting, $northing, $etrs89NationalGrid, $point->getCoordinateEpoch()); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
3 |
|
public function getVerticalAdjustment(ProjectedPoint $point): Metre |
|
73
|
|
|
{ |
|
74
|
3 |
|
$adjustment = $this->getAdjustment($point->getEasting()->asMetres(), $point->getNorthing()->asMetres()); |
|
75
|
|
|
|
|
76
|
3 |
|
return new Metre($adjustment[2]); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
11 |
|
private function getAdjustment(Metre $easting, Metre $northing): array |
|
80
|
|
|
{ |
|
81
|
11 |
|
$offsets = $this->interpolateBilinear($easting->getValue(), $northing->getValue()); |
|
82
|
|
|
|
|
83
|
11 |
|
return $offsets; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
11 |
|
private function getRecord(int $eastIndex, int $northIndex): GridValues |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
11 |
|
$record = $northIndex * 701 + $eastIndex + 1; |
|
89
|
|
|
|
|
90
|
|
|
// https://bugs.php.net/bug.php?id=62004 |
|
91
|
11 |
|
if (PHP_MAJOR_VERSION < 8) { |
|
92
|
|
|
--$record; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
11 |
|
$this->seek($record); |
|
96
|
11 |
|
$rawData = $this->fgetcsv(); |
|
97
|
|
|
|
|
98
|
11 |
|
return new GridValues((float) $rawData[1], (float) $rawData[2], [(float) $rawData[3], (float) $rawData[4], (float) $rawData[5]]); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths