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