1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHPCoord. |
4
|
|
|
* |
5
|
|
|
* @author Doug Wright |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace PHPCoord; |
10
|
|
|
|
11
|
|
|
use DateTime; |
12
|
|
|
use DateTimeImmutable; |
13
|
|
|
use DateTimeInterface; |
14
|
|
|
use PHPCoord\CoordinateOperation\AutoConversion; |
15
|
|
|
use PHPCoord\CoordinateOperation\ConvertiblePoint; |
16
|
|
|
use PHPCoord\CoordinateOperation\OSTNOSGM15Grid; |
17
|
|
|
use PHPCoord\CoordinateReferenceSystem\Compound; |
18
|
|
|
use PHPCoord\CoordinateReferenceSystem\CoordinateReferenceSystem; |
19
|
|
|
use PHPCoord\CoordinateReferenceSystem\Geographic2D; |
20
|
|
|
use PHPCoord\CoordinateReferenceSystem\Geographic3D; |
21
|
|
|
use PHPCoord\CoordinateReferenceSystem\Projected; |
|
|
|
|
22
|
|
|
use PHPCoord\CoordinateReferenceSystem\Vertical; |
23
|
|
|
use PHPCoord\CoordinateSystem\Cartesian; |
24
|
|
|
use PHPCoord\Datum\Datum; |
25
|
|
|
use PHPCoord\Exception\InvalidCoordinateReferenceSystemException; |
26
|
|
|
use PHPCoord\Exception\UnknownConversionException; |
27
|
|
|
use PHPCoord\UnitOfMeasure\Angle\Angle; |
28
|
|
|
use PHPCoord\UnitOfMeasure\Angle\Degree; |
29
|
|
|
use PHPCoord\UnitOfMeasure\Length\Length; |
30
|
|
|
use PHPCoord\UnitOfMeasure\Length\Metre; |
31
|
|
|
use PHPCoord\UnitOfMeasure\Scale\Unity; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Coordinate representing a point expressed in 2 different CRSs (2D horizontal + 1D Vertical). |
35
|
|
|
*/ |
36
|
|
|
class CompoundPoint extends Point implements ConvertiblePoint |
37
|
|
|
{ |
38
|
|
|
use AutoConversion { |
39
|
|
|
convert as protected autoConvert; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Horizontal point. |
44
|
|
|
* @var GeographicPoint|ProjectedPoint |
45
|
|
|
*/ |
46
|
|
|
protected Point $horizontalPoint; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Vertical point. |
50
|
|
|
*/ |
51
|
|
|
protected VerticalPoint $verticalPoint; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Coordinate reference system. |
55
|
|
|
*/ |
56
|
|
|
protected Compound $crs; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Coordinate epoch (date for which the specified coordinates represented this point). |
60
|
|
|
*/ |
61
|
72 |
|
protected ?DateTimeImmutable $epoch; |
62
|
|
|
|
63
|
72 |
|
/** |
64
|
72 |
|
* Constructor. |
65
|
72 |
|
* @param GeographicPoint|ProjectedPoint $horizontalPoint |
66
|
|
|
*/ |
67
|
72 |
|
protected function __construct(Point $horizontalPoint, VerticalPoint $verticalPoint, Compound $crs, ?DateTimeInterface $epoch = null) |
68
|
9 |
|
{ |
69
|
|
|
$this->horizontalPoint = $horizontalPoint; |
|
|
|
|
70
|
72 |
|
$this->verticalPoint = $verticalPoint; |
71
|
72 |
|
$this->crs = $crs; |
72
|
|
|
|
73
|
|
|
if ($epoch instanceof DateTime) { |
74
|
|
|
$epoch = DateTimeImmutable::createFromMutable($epoch); |
75
|
|
|
} |
76
|
72 |
|
$this->epoch = $epoch; |
77
|
|
|
} |
78
|
72 |
|
|
79
|
|
|
/** |
80
|
|
|
* @param GeographicPoint|ProjectedPoint $horizontalPoint |
81
|
63 |
|
*/ |
82
|
|
|
public static function create(Point $horizontalPoint, VerticalPoint $verticalPoint, Compound $crs, ?DateTimeInterface $epoch = null) |
83
|
63 |
|
{ |
84
|
|
|
return new static($horizontalPoint, $verticalPoint, $crs, $epoch); |
85
|
|
|
} |
86
|
54 |
|
|
87
|
|
|
public function getHorizontalPoint(): Point |
88
|
54 |
|
{ |
89
|
|
|
return $this->horizontalPoint; |
90
|
|
|
} |
91
|
72 |
|
|
92
|
|
|
public function getVerticalPoint(): VerticalPoint |
93
|
72 |
|
{ |
94
|
|
|
return $this->verticalPoint; |
95
|
|
|
} |
96
|
54 |
|
|
97
|
|
|
public function getCRS(): Compound |
98
|
54 |
|
{ |
99
|
|
|
return $this->crs; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getCoordinateEpoch(): ?DateTimeImmutable |
103
|
|
|
{ |
104
|
18 |
|
return $this->epoch; |
105
|
|
|
} |
106
|
|
|
|
107
|
18 |
|
/** |
108
|
18 |
|
* Calculate distance between two points. |
109
|
|
|
*/ |
110
|
|
|
public function calculateDistance(Point $to): Length |
111
|
18 |
|
{ |
112
|
9 |
|
try { |
113
|
|
|
if ($to instanceof ConvertiblePoint) { |
114
|
|
|
$to = $to->convert($this->crs); |
115
|
|
|
} |
116
|
9 |
|
} finally { |
117
|
|
|
if ($to->getCRS()->getSRID() !== $this->crs->getSRID()) { |
118
|
|
|
throw new InvalidCoordinateReferenceSystemException('Can only calculate distances between two points in the same CRS'); |
119
|
|
|
} |
120
|
45 |
|
|
121
|
|
|
/* @var CompoundPoint $to */ |
122
|
|
|
return $this->horizontalPoint->calculateDistance($to->horizontalPoint); |
123
|
45 |
|
} |
124
|
18 |
|
} |
125
|
9 |
|
|
126
|
|
|
public function convert(CoordinateReferenceSystem $to, bool $ignoreBoundaryRestrictions = false): Point |
127
|
9 |
|
{ |
128
|
|
|
try { |
129
|
|
|
return $this->autoConvert($to, $ignoreBoundaryRestrictions); |
130
|
|
|
} catch (UnknownConversionException $e) { |
131
|
|
|
if ($this->getHorizontalPoint() instanceof ConvertiblePoint) { |
132
|
9 |
|
// if 2D target, try again with just the horizontal component |
133
|
9 |
|
if (($to instanceof Geographic2D || $to instanceof Projected)) { |
134
|
|
|
return $this->getHorizontalPoint()->convert($to, $ignoreBoundaryRestrictions); |
135
|
9 |
|
} |
136
|
9 |
|
|
137
|
|
|
// try separate horizontal + vertical conversions and stitch results together |
138
|
9 |
|
if ($to instanceof Compound) { |
139
|
9 |
|
$newHorizontalPoint = $this->getHorizontalPoint()->convert($to->getHorizontal()); |
140
|
9 |
|
|
141
|
9 |
|
if ($this->getCRS()->getVertical()->getSRID() !== $to->getVertical()->getSRID()) { |
142
|
9 |
|
$path = $this->findOperationPath($this->getCRS()->getVertical(), $to->getVertical(), $ignoreBoundaryRestrictions); |
143
|
|
|
|
144
|
|
|
if ($path) { |
|
|
|
|
145
|
9 |
|
$newVerticalPoint = $this->getVerticalPoint(); |
146
|
|
|
foreach ($path as $step) { |
147
|
|
|
$target = CoordinateReferenceSystem::fromSRID($step['in_reverse'] ? $step['source_crs'] : $step['target_crs']); |
148
|
|
|
$newVerticalPoint = $newVerticalPoint->performOperation($step['operation'], $target, $step['in_reverse'], ['horizontalPoint' => $newHorizontalPoint]); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return static::create($newHorizontalPoint, $newVerticalPoint, $to, $this->epoch); |
152
|
|
|
} |
153
|
|
|
} |
154
|
27 |
|
} |
155
|
|
|
} |
156
|
27 |
|
throw $e; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function __toString(): string |
161
|
|
|
{ |
162
|
|
|
return "({$this->horizontalPoint}, {$this->verticalPoint})"; |
163
|
|
|
} |
164
|
18 |
|
|
165
|
|
|
/** |
166
|
|
|
* Geographic2D with Height Offsets. |
167
|
|
|
* This transformation allows calculation of coordinates in the target system by adding the parameter value to the |
168
|
|
|
* coordinate values of the point in the source system. |
169
|
|
|
*/ |
170
|
18 |
|
public function geographic2DWithHeightOffsets( |
171
|
18 |
|
Geographic3D $to, |
172
|
18 |
|
Angle $latitudeOffset, |
173
|
|
|
Angle $longitudeOffset, |
174
|
18 |
|
Length $geoidUndulation |
175
|
|
|
): GeographicPoint { |
176
|
|
|
$toLatitude = $this->getHorizontalPoint()->getLatitude()->add($latitudeOffset); |
|
|
|
|
177
|
|
|
$toLongitude = $this->getHorizontalPoint()->getLongitude()->add($longitudeOffset); |
|
|
|
|
178
|
|
|
$toHeight = $this->getVerticalPoint()->getHeight()->add($geoidUndulation); |
179
|
|
|
|
180
|
|
|
return GeographicPoint::create($toLatitude, $toLongitude, $toHeight, $to, $this->epoch); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Geog3D to Geog2D+GravityRelatedHeight (OSGM-GB). |
185
|
|
|
* Uses ETRS89 / National Grid as an intermediate coordinate system for bi-linear interpolation of gridded grid |
186
|
|
|
* coordinate differences. |
187
|
|
|
*/ |
188
|
|
|
public function geographic3DTo2DPlusGravityHeightOSGM15( |
189
|
|
|
Geographic3D $to, |
190
|
|
|
OSTNOSGM15Grid $geoidHeightCorrectionModelFile, |
191
|
|
|
string $EPSGCodeForInterpolationCRS |
|
|
|
|
192
|
|
|
): GeographicPoint { |
193
|
|
|
$osgb36NationalGrid = Projected::fromSRID(Projected::EPSG_OSGB36_BRITISH_NATIONAL_GRID); |
194
|
|
|
$etrs89NationalGrid = new Projected( |
195
|
|
|
'ETRS89 / National Grid', |
196
|
|
|
Cartesian::fromSRID(Cartesian::EPSG_2D_AXES_EASTING_NORTHING_E_N_ORIENTATIONS_EAST_NORTH_UOM_M), |
197
|
|
|
Datum::fromSRID(Datum::EPSG_EUROPEAN_TERRESTRIAL_REFERENCE_SYSTEM_1989_ENSEMBLE), |
198
|
|
|
$osgb36NationalGrid->getBoundingArea() |
199
|
|
|
); |
200
|
|
|
|
201
|
|
|
$projected = $this->horizontalPoint->transverseMercator($etrs89NationalGrid, new Degree(49), new Degree(-2), new Unity(0.9996012717), new Metre(400000), new Metre(-100000)); |
|
|
|
|
202
|
|
|
|
203
|
|
|
return GeographicPoint::create( |
204
|
|
|
$this->horizontalPoint->getLatitude(), |
205
|
|
|
$this->horizontalPoint->getLongitude(), |
206
|
|
|
$this->verticalPoint->getHeight()->add($geoidHeightCorrectionModelFile->getVerticalAdjustment($projected)), |
207
|
|
|
$to, |
208
|
|
|
$this->getCoordinateEpoch() |
209
|
|
|
); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|
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