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