Passed
Push — master ( 99135b...c08bef )
by Doug
16:52
created

geographic3DTo2DPlusGravityHeightGTX()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 15
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 23
ccs 16
cts 16
cp 1
crap 1
rs 9.7666
1
<?php
2
/**
3
 * PHPCoord.
4
 *
5
 * @author Doug Wright
6
 */
7
declare(strict_types=1);
8
9
namespace PHPCoord;
10
11
use function abs;
12
use function asinh;
13
use function atan;
14
use function atan2;
15
use function atanh;
16
use function cos;
17
use function cosh;
18
use DateTime;
19
use DateTimeImmutable;
20
use DateTimeInterface;
21
use function get_class;
22
use function hypot;
23
use function implode;
24
use function is_nan;
25
use function log;
26
use const M_E;
27
use const M_PI;
28
use function max;
29
use PHPCoord\CoordinateOperation\AutoConversion;
30
use PHPCoord\CoordinateOperation\ComplexNumber;
31
use PHPCoord\CoordinateOperation\ConvertiblePoint;
32
use PHPCoord\CoordinateOperation\GeocentricValue;
33
use PHPCoord\CoordinateOperation\GeographicValue;
34
use PHPCoord\CoordinateOperation\GTXGrid;
35
use PHPCoord\CoordinateOperation\IGNGeocentricTranslationGrid;
36
use PHPCoord\CoordinateOperation\NADCON5Grid;
37
use PHPCoord\CoordinateOperation\NTv2Grid;
38
use PHPCoord\CoordinateOperation\OSTNOSGM15Grid;
39
use PHPCoord\CoordinateReferenceSystem\Compound;
40
use PHPCoord\CoordinateReferenceSystem\Geocentric;
41
use PHPCoord\CoordinateReferenceSystem\Geographic;
42
use PHPCoord\CoordinateReferenceSystem\Geographic2D;
43
use PHPCoord\CoordinateReferenceSystem\Geographic3D;
44
use PHPCoord\CoordinateReferenceSystem\Projected;
0 ignored issues
show
Bug introduced by
The type PHPCoord\CoordinateReferenceSystem\Projected was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
45
use PHPCoord\CoordinateReferenceSystem\Vertical;
46
use PHPCoord\CoordinateSystem\Axis;
47
use PHPCoord\CoordinateSystem\Cartesian;
48
use PHPCoord\Datum\Datum;
49
use PHPCoord\Datum\Ellipsoid;
50
use PHPCoord\Exception\InvalidCoordinateReferenceSystemException;
51
use PHPCoord\Exception\UnknownAxisException;
52
use PHPCoord\Geometry\BoundingArea;
53
use PHPCoord\UnitOfMeasure\Angle\Angle;
54
use PHPCoord\UnitOfMeasure\Angle\ArcSecond;
55
use PHPCoord\UnitOfMeasure\Angle\Degree;
56
use PHPCoord\UnitOfMeasure\Angle\Radian;
57
use PHPCoord\UnitOfMeasure\Length\Length;
58
use PHPCoord\UnitOfMeasure\Length\Metre;
59
use PHPCoord\UnitOfMeasure\Scale\Coefficient;
60
use PHPCoord\UnitOfMeasure\Scale\Scale;
61
use PHPCoord\UnitOfMeasure\Scale\Unity;
62
use function sin;
63
use function sinh;
64
use function sprintf;
65
use function sqrt;
66
use function tan;
67
use TypeError;
68
69
/**
70
 * Coordinate representing a point on an ellipsoid.
71
 */
72
class GeographicPoint extends Point implements ConvertiblePoint
73
{
74
    use AutoConversion;
75
76
    /**
77
     * Latitude.
78
     */
79
    protected Angle $latitude;
80
81
    /**
82
     * Longitude.
83
     */
84
    protected Angle $longitude;
85
86
    /**
87
     * Height above ellipsoid (N.B. *not* height above ground, sea-level or anything else tangible).
88
     */
89
    protected ?Length $height;
90
91
    /**
92
     * Coordinate reference system.
93
     */
94
    protected Geographic $crs;
95
96
    /**
97
     * Coordinate epoch (date for which the specified coordinates represented this point).
98
     */
99
    protected ?DateTimeImmutable $epoch;
100
101 1499
    protected function __construct(Angle $latitude, Angle $longitude, ?Length $height, Geographic $crs, ?DateTimeInterface $epoch = null)
102
    {
103 1499
        if (!$crs instanceof Geographic2D && !$crs instanceof Geographic3D) {
104
            throw new TypeError(sprintf("A geographic point must be associated with a geographic CRS, but a '%s' CRS was given", get_class($crs)));
105
        }
106
107 1499
        if ($crs instanceof Geographic2D && $height !== null) {
108 9
            throw new InvalidCoordinateReferenceSystemException('A 2D geographic point must not include a height');
109
        }
110
111 1490
        if ($crs instanceof Geographic3D && $height === null) {
112 9
            throw new InvalidCoordinateReferenceSystemException('A 3D geographic point must include a height, none given');
113
        }
114
115 1481
        $this->crs = $crs;
116
117 1481
        $latitude = $this->normaliseLatitude($latitude);
118 1481
        $longitude = $this->normaliseLongitude($longitude);
119
120 1481
        $this->latitude = Angle::convert($latitude, $this->crs->getCoordinateSystem()->getAxisByName(Axis::GEODETIC_LATITUDE)->getUnitOfMeasureId());
121 1481
        $this->longitude = Angle::convert($longitude, $this->crs->getCoordinateSystem()->getAxisByName(Axis::GEODETIC_LONGITUDE)->getUnitOfMeasureId());
122
123 1481
        if ($height) {
124 171
            $this->height = Length::convert($height, $this->crs->getCoordinateSystem()->getAxisByName(Axis::ELLIPSOIDAL_HEIGHT)->getUnitOfMeasureId());
125
        } else {
126 1369
            $this->height = null;
127
        }
128
129 1481
        if ($epoch instanceof DateTime) {
130 9
            $epoch = DateTimeImmutable::createFromMutable($epoch);
131
        }
132 1481
        $this->epoch = $epoch;
133 1481
    }
134
135
    /**
136
     * @param Angle   $latitude  refer to CRS for preferred unit of measure, but any angle unit accepted
137
     * @param Angle   $longitude refer to CRS for preferred unit of measure, but any angle unit accepted
138
     * @param ?Length $height    refer to CRS for preferred unit of measure, but any length unit accepted
139
     */
140 1499
    public static function create(Angle $latitude, Angle $longitude, ?Length $height, Geographic $crs, ?DateTimeInterface $epoch = null): self
141
    {
142 1499
        return new static($latitude, $longitude, $height, $crs, $epoch);
143
    }
144
145 804
    public function getLatitude(): Angle
146
    {
147 804
        return $this->latitude;
148
    }
149
150 768
    public function getLongitude(): Angle
151
    {
152 768
        return $this->longitude;
153
    }
154
155 350
    public function getHeight(): ?Length
156
    {
157 350
        return $this->height;
158
    }
159
160 469
    public function getCRS(): Geographic
161
    {
162 469
        return $this->crs;
163
    }
164
165 204
    public function getCoordinateEpoch(): ?DateTimeImmutable
166
    {
167 204
        return $this->epoch;
168
    }
169
170 1481
    protected function normaliseLatitude(Angle $latitude): Angle
171
    {
172 1481
        if ($latitude->asDegrees()->getValue() > 90) {
173
            return new Degree(90);
174
        }
175 1481
        if ($latitude->asDegrees()->getValue() < -90) {
176
            return new Degree(-90);
177
        }
178
179 1481
        return $latitude;
180
    }
181
182 1481
    protected function normaliseLongitude(Angle $longitude): Angle
183
    {
184 1481
        while ($longitude->asDegrees()->getValue() > 180) {
185 9
            $longitude = $longitude->subtract(new Degree(360));
186
        }
187 1481
        while ($longitude->asDegrees()->getValue() <= -180) {
188
            $longitude = $longitude->add(new Degree(360));
189
        }
190
191 1481
        return $longitude;
192
    }
193
194
    /**
195
     * Calculate surface distance between two points.
196
     */
197 153
    public function calculateDistance(Point $to): Length
198
    {
199
        try {
200 153
            if ($to instanceof ConvertiblePoint) {
201 144
                $to = $to->convert($this->crs);
202
            }
203
        } finally {
204 153
            if ($to->getCRS()->getSRID() !== $this->crs->getSRID()) {
205 9
                throw new InvalidCoordinateReferenceSystemException('Can only calculate distances between two points in the same CRS');
206
            }
207
208
            /* @var GeographicPoint $to */
209 144
            return static::vincenty($this->asGeographicValue(), $to->asGeographicValue(), $this->getCRS()->getDatum()->getEllipsoid());
210
        }
211
    }
212
213 36
    public function __toString(): string
214
    {
215 36
        $values = [];
216 36
        foreach ($this->getCRS()->getCoordinateSystem()->getAxes() as $axis) {
217 36
            if ($axis->getName() === Axis::GEODETIC_LATITUDE) {
218 36
                $values[] = $this->latitude;
219 36
            } elseif ($axis->getName() === Axis::GEODETIC_LONGITUDE) {
220 36
                $values[] = $this->longitude;
221 9
            } elseif ($axis->getName() === Axis::ELLIPSOIDAL_HEIGHT) {
222 9
                $values[] = $this->height;
223
            } else {
224
                throw new UnknownAxisException(); // @codeCoverageIgnore
225
            }
226
        }
227
228 36
        return '(' . implode(', ', $values) . ')';
229
    }
230
231
    /**
232
     * Geographic/geocentric conversions
233
     * In applications it is often concatenated with the 3- 7- or 10-parameter transformations 9603, 9606, 9607 or
234
     * 9636 to form a geographic to geographic transformation.
235
     */
236 9
    public function geographicGeocentric(
237
        Geocentric $to
238
    ): GeocentricPoint {
239 9
        $geographicValue = new GeographicValue($this->latitude, $this->longitude, $this->height, $this->crs->getDatum());
240 9
        $asGeocentric = $geographicValue->asGeocentricValue();
241
242 9
        return GeocentricPoint::create($asGeocentric->getX(), $asGeocentric->getY(), $asGeocentric->getZ(), $to, $this->epoch);
243
    }
244
245
    /**
246
     * Coordinate Frame rotation (geog2D/geog3D domain)
247
     * Note the analogy with the Position Vector tfm (codes 9606/1037) but beware of the differences!  The Position Vector
248
     * convention is used by IAG and recommended by ISO 19111. See methods 1032/1038/9607 for similar tfms operating
249
     * between other CRS types.
250
     */
251 54
    public function coordinateFrameRotation(
252
        Geographic $to,
253
        Length $xAxisTranslation,
254
        Length $yAxisTranslation,
255
        Length $zAxisTranslation,
256
        Angle $xAxisRotation,
257
        Angle $yAxisRotation,
258
        Angle $zAxisRotation,
259
        Scale $scaleDifference
260
    ): self {
261 54
        return $this->coordinateFrameMolodenskyBadekas(
262 54
            $to,
263
            $xAxisTranslation,
264
            $yAxisTranslation,
265
            $zAxisTranslation,
266
            $xAxisRotation,
267
            $yAxisRotation,
268
            $zAxisRotation,
269
            $scaleDifference,
270 54
            new Metre(0),
271 54
            new Metre(0),
272 54
            new Metre(0)
273
        );
274
    }
275
276
    /**
277
     * Molodensky-Badekas (CF geog2D/geog3D domain)
278
     * See method codes 1034 and 1039/9636 for this operation in other coordinate domains and method code 1062/1063 for the
279
     * opposite rotation convention in geographic 2D domain.
280
     */
281 72
    public function coordinateFrameMolodenskyBadekas(
282
        Geographic $to,
283
        Length $xAxisTranslation,
284
        Length $yAxisTranslation,
285
        Length $zAxisTranslation,
286
        Angle $xAxisRotation,
287
        Angle $yAxisRotation,
288
        Angle $zAxisRotation,
289
        Scale $scaleDifference,
290
        Length $ordinate1OfEvaluationPoint,
291
        Length $ordinate2OfEvaluationPoint,
292
        Length $ordinate3OfEvaluationPoint
293
    ): self {
294 72
        $geographicValue = new GeographicValue($this->latitude, $this->longitude, $this->height, $this->crs->getDatum());
295 72
        $asGeocentric = $geographicValue->asGeocentricValue();
296
297 72
        $xs = $asGeocentric->getX()->asMetres()->getValue();
298 72
        $ys = $asGeocentric->getY()->asMetres()->getValue();
299 72
        $zs = $asGeocentric->getZ()->asMetres()->getValue();
300 72
        $tx = $xAxisTranslation->asMetres()->getValue();
301 72
        $ty = $yAxisTranslation->asMetres()->getValue();
302 72
        $tz = $zAxisTranslation->asMetres()->getValue();
303 72
        $rx = $xAxisRotation->asRadians()->getValue();
304 72
        $ry = $yAxisRotation->asRadians()->getValue();
305 72
        $rz = $zAxisRotation->asRadians()->getValue();
306 72
        $M = 1 + $scaleDifference->asUnity()->getValue();
307 72
        $xp = $ordinate1OfEvaluationPoint->asMetres()->getValue();
308 72
        $yp = $ordinate2OfEvaluationPoint->asMetres()->getValue();
309 72
        $zp = $ordinate3OfEvaluationPoint->asMetres()->getValue();
310
311 72
        $xt = $M * ((($xs - $xp) * 1) + (($ys - $yp) * $rz) + (($zs - $zp) * -$ry)) + $tx + $xp;
312 72
        $yt = $M * ((($xs - $xp) * -$rz) + (($ys - $yp) * 1) + (($zs - $zp) * $rx)) + $ty + $yp;
313 72
        $zt = $M * ((($xs - $xp) * $ry) + (($ys - $yp) * -$rx) + (($zs - $zp) * 1)) + $tz + $zp;
314 72
        $newGeocentric = new GeocentricValue(new Metre($xt), new Metre($yt), new Metre($zt), $to->getDatum());
315 72
        $newGeographic = $newGeocentric->asGeographicValue();
316
317 72
        return static::create($newGeographic->getLatitude(), $newGeographic->getLongitude(), $to instanceof Geographic3D ? $newGeographic->getHeight() : null, $to, $this->epoch);
318
    }
319
320
    /**
321
     * Position Vector transformation (geog2D/geog3D domain)
322
     * Note the analogy with the Coordinate Frame rotation (code 9607/1038) but beware of the differences!  The Position
323
     * Vector convention is used by IAG and recommended by ISO 19111. See methods 1033/1037/9606 for similar tfms
324
     * operating between other CRS types.
325
     */
326 199
    public function positionVectorTransformation(
327
        Geographic $to,
328
        Length $xAxisTranslation,
329
        Length $yAxisTranslation,
330
        Length $zAxisTranslation,
331
        Angle $xAxisRotation,
332
        Angle $yAxisRotation,
333
        Angle $zAxisRotation,
334
        Scale $scaleDifference
335
    ): self {
336 199
        return $this->positionVectorMolodenskyBadekas(
337 199
            $to,
338
            $xAxisTranslation,
339
            $yAxisTranslation,
340
            $zAxisTranslation,
341
            $xAxisRotation,
342
            $yAxisRotation,
343
            $zAxisRotation,
344
            $scaleDifference,
345 199
            new Metre(0),
346 199
            new Metre(0),
347 199
            new Metre(0)
348
        );
349
    }
350
351
    /**
352
     * Molodensky-Badekas (PV geog2D/geog3D domain)
353
     * See method codes 1061 and 1062/1063 for this operation in other coordinate domains and method code 1039/9636 for opposite
354
     * rotation in geographic 2D/3D domain.
355
     */
356 217
    public function positionVectorMolodenskyBadekas(
357
        Geographic $to,
358
        Length $xAxisTranslation,
359
        Length $yAxisTranslation,
360
        Length $zAxisTranslation,
361
        Angle $xAxisRotation,
362
        Angle $yAxisRotation,
363
        Angle $zAxisRotation,
364
        Scale $scaleDifference,
365
        Length $ordinate1OfEvaluationPoint,
366
        Length $ordinate2OfEvaluationPoint,
367
        Length $ordinate3OfEvaluationPoint
368
    ): self {
369 217
        $geographicValue = new GeographicValue($this->latitude, $this->longitude, $this->height, $this->crs->getDatum());
370 217
        $asGeocentric = $geographicValue->asGeocentricValue();
371
372 217
        $xs = $asGeocentric->getX()->asMetres()->getValue();
373 217
        $ys = $asGeocentric->getY()->asMetres()->getValue();
374 217
        $zs = $asGeocentric->getZ()->asMetres()->getValue();
375 217
        $tx = $xAxisTranslation->asMetres()->getValue();
376 217
        $ty = $yAxisTranslation->asMetres()->getValue();
377 217
        $tz = $zAxisTranslation->asMetres()->getValue();
378 217
        $rx = $xAxisRotation->asRadians()->getValue();
379 217
        $ry = $yAxisRotation->asRadians()->getValue();
380 217
        $rz = $zAxisRotation->asRadians()->getValue();
381 217
        $M = 1 + $scaleDifference->asUnity()->getValue();
382 217
        $xp = $ordinate1OfEvaluationPoint->asMetres()->getValue();
383 217
        $yp = $ordinate2OfEvaluationPoint->asMetres()->getValue();
384 217
        $zp = $ordinate3OfEvaluationPoint->asMetres()->getValue();
385
386 217
        $xt = $M * ((($xs - $xp) * 1) + (($ys - $yp) * -$rz) + (($zs - $zp) * $ry)) + $tx + $xp;
387 217
        $yt = $M * ((($xs - $xp) * $rz) + (($ys - $yp) * 1) + (($zs - $zp) * -$rx)) + $ty + $yp;
388 217
        $zt = $M * ((($xs - $xp) * -$ry) + (($ys - $yp) * $rx) + (($zs - $zp) * 1)) + $tz + $zp;
389 217
        $newGeocentric = new GeocentricValue(new Metre($xt), new Metre($yt), new Metre($zt), $to->getDatum());
390 217
        $newGeographic = $newGeocentric->asGeographicValue();
391
392 217
        return static::create($newGeographic->getLatitude(), $newGeographic->getLongitude(), $to instanceof Geographic3D ? $newGeographic->getHeight() : null, $to, $this->epoch);
393
    }
394
395
    /**
396
     * Geocentric translations
397
     * This method allows calculation of geocentric coords in the target system by adding the parameter values to the
398
     * corresponding coordinates of the point in the source system. See methods 1031 and 1035 for similar tfms
399
     * operating between other CRSs types.
400
     */
401 96
    public function geocentricTranslation(
402
        Geographic $to,
403
        Length $xAxisTranslation,
404
        Length $yAxisTranslation,
405
        Length $zAxisTranslation
406
    ): self {
407 96
        return $this->positionVectorTransformation(
408 96
            $to,
409
            $xAxisTranslation,
410
            $yAxisTranslation,
411
            $zAxisTranslation,
412 96
            new Radian(0),
413 96
            new Radian(0),
414 96
            new Radian(0),
415 96
            new Unity(0)
416
        );
417
    }
418
419
    /**
420
     * Abridged Molodensky
421
     * This transformation is a truncated Taylor series expansion of a transformation between two geographic coordinate
422
     * systems, modelled as a set of geocentric translations.
423
     */
424 18
    public function abridgedMolodensky(
425
        Geographic $to,
426
        Length $xAxisTranslation,
427
        Length $yAxisTranslation,
428
        Length $zAxisTranslation,
429
        Length $differenceInSemiMajorAxis,
430
        Scale $differenceInFlattening
431
    ): self {
432 18
        $latitude = $this->latitude->asRadians()->getValue();
433 18
        $longitude = $this->longitude->asRadians()->getValue();
434 18
        $fromHeight = $this->height ? $this->height->asMetres()->getValue() : 0;
435 18
        $tx = $xAxisTranslation->asMetres()->getValue();
436 18
        $ty = $yAxisTranslation->asMetres()->getValue();
437 18
        $tz = $zAxisTranslation->asMetres()->getValue();
438 18
        $da = $differenceInSemiMajorAxis->asMetres()->getValue();
439 18
        $df = $differenceInFlattening->asUnity()->getValue();
440
441 18
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
442 18
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
443
444 18
        $rho = $a * (1 - $e2) / (1 - $e2 * sin($latitude) ** 2) ** (3 / 2);
445 18
        $nu = $a / sqrt(1 - $e2 * (sin($latitude) ** 2));
446
447 18
        $f = $this->crs->getDatum()->getEllipsoid()->getInverseFlattening();
448
449 18
        $dLatitude = ((-$tx * sin($latitude) * cos($longitude)) - ($ty * sin($latitude) * sin($longitude)) + ($tz * cos($latitude)) + ((($a * $df) + ($this->crs->getDatum()->getEllipsoid()->getInverseFlattening() * $da)) * sin(2 * $latitude))) / ($rho * sin((new ArcSecond(1))->asRadians()->getValue()));
450 18
        $dLongitude = (-$tx * sin($longitude) + $ty * cos($longitude)) / (($nu * cos($latitude)) * sin((new ArcSecond(1))->asRadians()->getValue()));
451 18
        $dHeight = ($tx * cos($latitude) * cos($longitude)) + ($ty * cos($latitude) * sin($longitude)) + ($tz * sin($latitude)) + (($a * $df + $f * $da) * (sin($latitude) ** 2)) - $da;
452
453 18
        $toLatitude = $latitude + (new ArcSecond($dLatitude))->asRadians()->getValue();
454 18
        $toLongitude = $longitude + (new ArcSecond($dLongitude))->asRadians()->getValue();
455 18
        $toHeight = $fromHeight + $dHeight;
456
457 18
        return static::create(new Radian($toLatitude), new Radian($toLongitude), $to instanceof Geographic3D ? new Metre($toHeight) : null, $to, $this->epoch);
458
    }
459
460
    /**
461
     * Molodensky
462
     * See Abridged Molodensky.
463
     */
464 18
    public function molodensky(
465
        Geographic $to,
466
        Length $xAxisTranslation,
467
        Length $yAxisTranslation,
468
        Length $zAxisTranslation,
469
        Length $differenceInSemiMajorAxis,
470
        Scale $differenceInFlattening
471
    ): self {
472 18
        $latitude = $this->latitude->asRadians()->getValue();
473 18
        $longitude = $this->longitude->asRadians()->getValue();
474 18
        $fromHeight = $this->height ? $this->height->asMetres()->getValue() : 0;
475 18
        $tx = $xAxisTranslation->asMetres()->getValue();
476 18
        $ty = $yAxisTranslation->asMetres()->getValue();
477 18
        $tz = $zAxisTranslation->asMetres()->getValue();
478 18
        $da = $differenceInSemiMajorAxis->asMetres()->getValue();
479 18
        $df = $differenceInFlattening->asUnity()->getValue();
480
481 18
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
482 18
        $b = $this->crs->getDatum()->getEllipsoid()->getSemiMinorAxis()->asMetres()->getValue();
483 18
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
484
485 18
        $rho = $a * (1 - $e2) / (1 - $e2 * sin($latitude) ** 2) ** (3 / 2);
486 18
        $nu = $a / sqrt(1 - $e2 * (sin($latitude) ** 2));
487
488 18
        $f = $this->crs->getDatum()->getEllipsoid()->getInverseFlattening();
0 ignored issues
show
Unused Code introduced by
The assignment to $f is dead and can be removed.
Loading history...
489
490 18
        $dLatitude = ((-$tx * sin($latitude) * cos($longitude)) - ($ty * sin($latitude) * sin($longitude)) + ($tz * cos($latitude)) + ($da * ($nu * $e2 * sin($latitude) * cos($latitude)) / $a + $df * ($rho * ($a / $b) + $nu * ($b / $a)) * sin($latitude) * cos($latitude))) / (($rho + $fromHeight) * sin((new ArcSecond(1))->asRadians()->getValue()));
491 18
        $dLongitude = (-$tx * sin($longitude) + $ty * cos($longitude)) / ((($nu + $fromHeight) * cos($latitude)) * sin((new ArcSecond(1))->asRadians()->getValue()));
492 18
        $dHeight = ($tx * cos($latitude) * cos($longitude)) + ($ty * cos($latitude) * sin($longitude)) + ($tz * sin($latitude)) - $da * $a / $nu + $df * $b / $a * $nu * sin($latitude) ** 2;
493
494 18
        $toLatitude = $latitude + (new ArcSecond($dLatitude))->asRadians()->getValue();
495 18
        $toLongitude = $longitude + (new ArcSecond($dLongitude))->asRadians()->getValue();
496 18
        $toHeight = $fromHeight + $dHeight;
497
498 18
        return static::create(new Radian($toLatitude), new Radian($toLongitude), $to instanceof Geographic3D ? new Metre($toHeight) : null, $to, $this->epoch);
499
    }
500
501
    /**
502
     * Albers Equal Area.
503
     */
504 18
    public function albersEqualArea(
505
        Projected $to,
506
        Angle $latitudeOfFalseOrigin,
507
        Angle $longitudeOfFalseOrigin,
508
        Angle $latitudeOf1stStandardParallel,
509
        Angle $latitudeOf2ndStandardParallel,
510
        Length $eastingAtFalseOrigin,
511
        Length $northingAtFalseOrigin
512
    ): ProjectedPoint {
513 18
        $latitude = $this->latitude->asRadians()->getValue();
514 18
        $longitude = $this->longitude->asRadians()->getValue();
0 ignored issues
show
Unused Code introduced by
The assignment to $longitude is dead and can be removed.
Loading history...
515 18
        $phiOrigin = $latitudeOfFalseOrigin->asRadians()->getValue();
516 18
        $phi1 = $latitudeOf1stStandardParallel->asRadians()->getValue();
517 18
        $phi2 = $latitudeOf2ndStandardParallel->asRadians()->getValue();
518 18
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
519 18
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
520 18
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
521
522 18
        $centralMeridianFirstParallel = cos($phi1) / sqrt(1 - ($e2 * sin($phi1) ** 2));
523 18
        $centralMeridianSecondParallel = cos($phi2) / sqrt(1 - ($e2 * sin($phi2) ** 2));
524
525 18
        $alpha = (1 - $e2) * (sin($latitude) / (1 - $e2 * sin($latitude) ** 2) - (1 / 2 / $e) * log((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))));
526 18
        $alphaOrigin = (1 - $e2) * (sin($phiOrigin) / (1 - $e2 * sin($phiOrigin) ** 2) - (1 / 2 / $e) * log((1 - $e * sin($phiOrigin)) / (1 + $e * sin($phiOrigin))));
527 18
        $alphaFirstParallel = (1 - $e2) * (sin($phi1) / (1 - $e2 * sin($phi1) ** 2) - (1 / 2 / $e) * log((1 - $e * sin($phi1)) / (1 + $e * sin($phi1))));
528 18
        $alphaSecondParallel = (1 - $e2) * (sin($phi2) / (1 - $e2 * sin($phi2) ** 2) - (1 / 2 / $e) * log((1 - $e * sin($phi2)) / (1 + $e * sin($phi2))));
529
530 18
        $n = ($centralMeridianFirstParallel ** 2 - $centralMeridianSecondParallel ** 2) / ($alphaSecondParallel - $alphaFirstParallel);
531 18
        $C = $centralMeridianFirstParallel ** 2 + $n * $alphaFirstParallel;
532 18
        $theta = $n * $this->normaliseLongitude($this->longitude->subtract($longitudeOfFalseOrigin))->asRadians()->getValue();
533 18
        $rho = $a * sqrt($C - $n * $alpha) / $n;
534 18
        $rhoOrigin = ($a * sqrt($C - $n * $alphaOrigin)) / $n;
535
536 18
        $easting = $eastingAtFalseOrigin->asMetres()->getValue() + ($rho * sin($theta));
537 18
        $northing = $northingAtFalseOrigin->asMetres()->getValue() + $rhoOrigin - ($rho * cos($theta));
538
539 18
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
540
    }
541
542
    /**
543
     * American Polyconic.
544
     */
545 9
    public function americanPolyconic(
546
        Projected $to,
547
        Angle $latitudeOfNaturalOrigin,
548
        Angle $longitudeOfNaturalOrigin,
549
        Length $falseEasting,
550
        Length $falseNorthing
551
    ): ProjectedPoint {
552 9
        $latitude = $this->latitude->asRadians()->getValue();
553 9
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
554 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
555 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
556 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
557 9
        $e4 = $e ** 4;
558 9
        $e6 = $e ** 6;
559
560 9
        $M = $a * ((1 - $e2 / 4 - 3 * $e4 / 64 - 5 * $e6 / 256) * $latitude - (3 * $e2 / 8 + 3 * $e4 / 32 + 45 * $e6 / 1024) * sin(2 * $latitude) + (15 * $e4 / 256 + 45 * $e6 / 1024) * sin(4 * $latitude) - (35 * $e6 / 3072) * sin(6 * $latitude));
561 9
        $MO = $a * ((1 - $e2 / 4 - 3 * $e4 / 64 - 5 * $e6 / 256) * $latitudeOrigin - (3 * $e2 / 8 + 3 * $e4 / 32 + 45 * $e6 / 1024) * sin(2 * $latitudeOrigin) + (15 * $e4 / 256 + 45 * $e6 / 1024) * sin(4 * $latitudeOrigin) - (35 * $e6 / 3072) * sin(6 * $latitudeOrigin));
562
563 9
        if ($latitude === 0.0) {
0 ignored issues
show
introduced by
The condition $latitude === 0.0 is always false.
Loading history...
564
            $easting = $falseEasting->asMetres()->getValue() + $a * $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue();
565
            $northing = $falseNorthing->asMetres()->getValue() - $MO;
566
        } else {
567 9
            $L = $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue() * sin($latitude);
568 9
            $nu = $a / sqrt(1 - $e2 * sin($latitude) ** 2);
569
570 9
            $easting = $falseEasting->asMetres()->getValue() + $nu * 1 / tan($latitude) * sin($L);
571 9
            $northing = $falseNorthing->asMetres()->getValue() + $M - $MO + $nu * 1 / tan($latitude) * (1 - cos($L));
572
        }
573
574 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
575
    }
576
577
    /**
578
     * Bonne.
579
     */
580 9
    public function bonne(
581
        Projected $to,
582
        Angle $latitudeOfNaturalOrigin,
583
        Angle $longitudeOfNaturalOrigin,
584
        Length $falseEasting,
585
        Length $falseNorthing
586
    ): ProjectedPoint {
587 9
        $latitude = $this->latitude->asRadians()->getValue();
588 9
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
589 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
590 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
591 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
592 9
        $e4 = $e ** 4;
593 9
        $e6 = $e ** 6;
594
595 9
        $m = cos($latitude) / sqrt(1 - $e2 * sin($latitude) ** 2);
596 9
        $mO = cos($latitudeOrigin) / sqrt(1 - $e2 * sin($latitudeOrigin) ** 2);
597
598 9
        $M = $a * ((1 - $e2 / 4 - 3 * $e4 / 64 - 5 * $e6 / 256) * $latitude - (3 * $e2 / 8 + 3 * $e4 / 32 + 45 * $e6 / 1024) * sin(2 * $latitude) + (15 * $e4 / 256 + 45 * $e6 / 1024) * sin(4 * $latitude) - (35 * $e6 / 3072) * sin(6 * $latitude));
599 9
        $MO = $a * ((1 - $e2 / 4 - 3 * $e4 / 64 - 5 * $e6 / 256) * $latitudeOrigin - (3 * $e2 / 8 + 3 * $e4 / 32 + 45 * $e6 / 1024) * sin(2 * $latitudeOrigin) + (15 * $e4 / 256 + 45 * $e6 / 1024) * sin(4 * $latitudeOrigin) - (35 * $e6 / 3072) * sin(6 * $latitudeOrigin));
600
601 9
        $rho = $a * $mO / sin($latitudeOrigin) + $MO - $M;
602 9
        $tau = $a * $m * $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue() / $rho;
603
604 9
        $easting = $falseEasting->asMetres()->getValue() + ($rho * sin($tau));
605 9
        $northing = $falseNorthing->asMetres()->getValue() + (($a * $mO / sin($latitudeOrigin) - $rho * cos($tau)));
606
607 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
608
    }
609
610
    /**
611
     * Bonne South Orientated.
612
     */
613 9
    public function bonneSouthOrientated(
614
        Projected $to,
615
        Angle $latitudeOfNaturalOrigin,
616
        Angle $longitudeOfNaturalOrigin,
617
        Length $falseEasting,
618
        Length $falseNorthing
619
    ): ProjectedPoint {
620 9
        $latitude = $this->latitude->asRadians()->getValue();
621 9
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
622 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
623 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
624 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
625 9
        $e4 = $e ** 4;
626 9
        $e6 = $e ** 6;
627
628 9
        $m = cos($latitude) / sqrt(1 - $e2 * sin($latitude) ** 2);
629 9
        $mO = cos($latitudeOrigin) / sqrt(1 - $e2 * sin($latitudeOrigin) ** 2);
630
631 9
        $M = $a * ((1 - $e2 / 4 - 3 * $e4 / 64 - 5 * $e6 / 256) * $latitude - (3 * $e2 / 8 + 3 * $e4 / 32 + 45 * $e6 / 1024) * sin(2 * $latitude) + (15 * $e4 / 256 + 45 * $e6 / 1024) * sin(4 * $latitude) - (35 * $e6 / 3072) * sin(6 * $latitude));
632 9
        $MO = $a * ((1 - $e2 / 4 - 3 * $e4 / 64 - 5 * $e6 / 256) * $latitudeOrigin - (3 * $e2 / 8 + 3 * $e4 / 32 + 45 * $e6 / 1024) * sin(2 * $latitudeOrigin) + (15 * $e4 / 256 + 45 * $e6 / 1024) * sin(4 * $latitudeOrigin) - (35 * $e6 / 3072) * sin(6 * $latitudeOrigin));
633
634 9
        $rho = $a * $mO / sin($latitudeOrigin) + $MO - $M;
635 9
        $tau = $a * $m * $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue() / $rho;
636
637 9
        $westing = $falseEasting->asMetres()->getValue() - ($rho * sin($tau));
638 9
        $southing = $falseNorthing->asMetres()->getValue() - (($a * $mO / sin($latitudeOrigin) - $rho * cos($tau)));
639
640 9
        return ProjectedPoint::create(new Metre(-$westing), new Metre(-$southing), new Metre($westing), new Metre($southing), $to, $this->epoch);
641
    }
642
643
    /**
644
     * Cassini-Soldner.
645
     */
646 9
    public function cassiniSoldner(
647
        Projected $to,
648
        Angle $latitudeOfNaturalOrigin,
649
        Angle $longitudeOfNaturalOrigin,
650
        Length $falseEasting,
651
        Length $falseNorthing
652
    ): ProjectedPoint {
653 9
        $latitude = $this->latitude->asRadians()->getValue();
654 9
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
655 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
656 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
657 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
658 9
        $e4 = $e ** 4;
659 9
        $e6 = $e ** 6;
660
661 9
        $M = $a * ((1 - $e2 / 4 - 3 * $e4 / 64 - 5 * $e6 / 256) * $latitude - (3 * $e2 / 8 + 3 * $e4 / 32 + 45 * $e6 / 1024) * sin(2 * $latitude) + (15 * $e4 / 256 + 45 * $e6 / 1024) * sin(4 * $latitude) - (35 * $e6 / 3072) * sin(6 * $latitude));
662 9
        $MO = $a * ((1 - $e2 / 4 - 3 * $e4 / 64 - 5 * $e6 / 256) * $latitudeOrigin - (3 * $e2 / 8 + 3 * $e4 / 32 + 45 * $e6 / 1024) * sin(2 * $latitudeOrigin) + (15 * $e4 / 256 + 45 * $e6 / 1024) * sin(4 * $latitudeOrigin) - (35 * $e6 / 3072) * sin(6 * $latitudeOrigin));
663
664 9
        $A = $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue() * cos($latitude);
665 9
        $T = tan($latitude) ** 2;
666 9
        $C = $e2 * cos($latitude) ** 2 / (1 - $e2);
667 9
        $nu = $a / sqrt(1 - $e2 * (sin($latitude) ** 2));
668 9
        $X = $M - $MO + $nu * tan($latitude) * ($A ** 2 / 2 + (5 - $T + 6 * $C) * $A ** 4 / 24);
669
670 9
        $easting = $falseEasting->asMetres()->getValue() + $nu * ($A - $T * $A ** 3 / 6 - (8 - $T + 8 * $C) * $T * $A ** 5 / 120);
671 9
        $northing = $falseNorthing->asMetres()->getValue() + $X;
672
673 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
674
    }
675
676
    /**
677
     * Hyperbolic Cassini-Soldner.
678
     */
679 18
    public function hyperbolicCassiniSoldner(
680
        Projected $to,
681
        Angle $latitudeOfNaturalOrigin,
682
        Angle $longitudeOfNaturalOrigin,
683
        Length $falseEasting,
684
        Length $falseNorthing
685
    ): ProjectedPoint {
686 18
        $latitude = $this->latitude->asRadians()->getValue();
687 18
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
688 18
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
689 18
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
690 18
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
691 18
        $e4 = $e ** 4;
692 18
        $e6 = $e ** 6;
693
694 18
        $M = $a * ((1 - $e2 / 4 - 3 * $e4 / 64 - 5 * $e6 / 256) * $latitude - (3 * $e2 / 8 + 3 * $e4 / 32 + 45 * $e6 / 1024) * sin(2 * $latitude) + (15 * $e4 / 256 + 45 * $e6 / 1024) * sin(4 * $latitude) - (35 * $e6 / 3072) * sin(6 * $latitude));
695 18
        $MO = $a * ((1 - $e2 / 4 - 3 * $e4 / 64 - 5 * $e6 / 256) * $latitudeOrigin - (3 * $e2 / 8 + 3 * $e4 / 32 + 45 * $e6 / 1024) * sin(2 * $latitudeOrigin) + (15 * $e4 / 256 + 45 * $e6 / 1024) * sin(4 * $latitudeOrigin) - (35 * $e6 / 3072) * sin(6 * $latitudeOrigin));
696
697 18
        $A = $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue() * cos($latitude);
698 18
        $T = tan($latitude) ** 2;
699 18
        $C = $e2 * cos($latitude) ** 2 / (1 - $e2);
700 18
        $nu = $a / sqrt(1 - $e2 * (sin($latitude) ** 2));
701 18
        $rho = $a * (1 - $e2) / (1 - $e2 * sin($latitude) ** 2) ** (3 / 2);
702 18
        $X = $M - $MO + $nu * tan($latitude) * ($A ** 2 / 2 + (5 - $T + 6 * $C) * $A ** 4 / 24);
703
704 18
        $easting = $falseEasting->asMetres()->getValue() + $nu * ($A - $T * $A ** 3 / 6 - (8 - $T + 8 * $C) * $T * $A ** 5 / 120);
705 18
        $northing = $falseNorthing->asMetres()->getValue() + $X - ($X ** 3 / (6 * $rho * $nu));
706
707 18
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
708
    }
709
710
    /**
711
     * Colombia Urban.
712
     */
713 9
    public function columbiaUrban(
714
        Projected $to,
715
        Angle $latitudeOfNaturalOrigin,
716
        Angle $longitudeOfNaturalOrigin,
717
        Length $falseEasting,
718
        Length $falseNorthing,
719
        Length $projectionPlaneOriginHeight
720
    ): ProjectedPoint {
721 9
        $latitude = $this->latitude->asRadians()->getValue();
722 9
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
723 9
        $heightOrigin = $projectionPlaneOriginHeight->asMetres()->getValue();
724 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
725 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
726
727 9
        $rhoOrigin = $a * (1 - $e2) / (1 - $e2 * sin($latitudeOrigin) ** 2) ** (3 / 2);
728 9
        $rhoMid = $a * (1 - $e2) / (1 - $e2 * sin(($latitude + $latitudeOrigin) / 2) ** 2) ** (3 / 2);
729
730 9
        $nu = $a / sqrt(1 - $e2 * (sin($latitude) ** 2));
731 9
        $nuOrigin = $a / sqrt(1 - $e2 * (sin($latitudeOrigin) ** 2));
732
733 9
        $A = 1 + $heightOrigin / $nuOrigin;
734 9
        $B = tan($latitudeOrigin) / (2 * $rhoOrigin * $nuOrigin);
735 9
        $G = 1 + $heightOrigin / $rhoMid;
736
737 9
        $easting = $falseEasting->asMetres()->getValue() + $A * $nu * cos($latitude) * $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue();
738 9
        $northing = $falseNorthing->asMetres()->getValue() + $G * $rhoOrigin * (($latitude - $latitudeOrigin) + ($B * $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue() ** 2 * $nu ** 2 * cos($latitude) ** 2));
739
740 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
741
    }
742
743
    /**
744
     * Equal Earth.
745
     */
746 9
    public function equalEarth(
747
        Projected $to,
748
        Angle $longitudeOfNaturalOrigin,
749
        Length $falseEasting,
750
        Length $falseNorthing
751
    ): ProjectedPoint {
752 9
        $latitude = $this->latitude->asRadians()->getValue();
753 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
754 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
755 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
756
757 9
        $q = (1 - $e2) * ((sin($latitude) / (1 - $e2 * sin($latitude) ** 2)) - (1 / (2 * $e) * log((1 - $e * sin($latitude)) / (1 + $e * sin($latitude)))));
758 9
        $qP = (1 - $e2) * ((1 / (1 - $e2)) - (1 / (2 * $e) * log((1 - $e) / (1 + $e))));
759 9
        $beta = self::asin($q / $qP);
760 9
        $theta = self::asin(sin($beta) * sqrt(3) / 2);
761 9
        $Rq = $a * sqrt($qP / 2);
762
763 9
        $easting = $falseEasting->asMetres()->getValue() + ($Rq * 2 * $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue() * cos($theta)) / (sqrt(3) * (1.340264 - 0.243318 * $theta ** 2 + $theta ** 6 * (0.006251 + 0.034164 * $theta ** 2)));
764 9
        $northing = $falseNorthing->asMetres()->getValue() + $Rq * $theta * (1.340264 - 0.081106 * $theta ** 2 + $theta ** 6 * (0.000893 + 0.003796 * $theta ** 2));
765
766 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
767
    }
768
769
    /**
770
     * Equidistant Cylindrical
771
     * See method code 1029 for spherical development. See also Pseudo Plate Carree, method code 9825.
772
     */
773 9
    public function equidistantCylindrical(
774
        Projected $to,
775
        Angle $latitudeOf1stStandardParallel,
776
        Angle $longitudeOfNaturalOrigin,
777
        Length $falseEasting,
778
        Length $falseNorthing
779
    ): ProjectedPoint {
780 9
        $latitude = $this->latitude->asRadians()->getValue();
781 9
        $latitudeFirstParallel = $latitudeOf1stStandardParallel->asRadians()->getValue();
782 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
783 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
784 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
785 9
        $e4 = $e ** 4;
786 9
        $e6 = $e ** 6;
787 9
        $e8 = $e ** 8;
788 9
        $e10 = $e ** 10;
789 9
        $e12 = $e ** 12;
790 9
        $e14 = $e ** 14;
791
792 9
        $nu1 = $a / sqrt(1 - $e2 * sin($latitudeFirstParallel) ** 2);
793
794
        $M = $a * (
795 9
            (1 - 1 / 4 * $e2 - 3 / 64 * $e4 - 5 / 256 * $e6 - 175 / 16384 * $e8 - 441 / 65536 * $e10 - 4851 / 1048576 * $e12 - 14157 / 4194304 * $e14) * $latitude +
796 9
            (-3 / 8 * $e2 - 3 / 32 * $e4 - 45 / 1024 * $e6 - 105 / 4096 * $e8 - 2205 / 131072 * $e10 - 6237 / 524288 * $e12 - 297297 / 33554432 * $e14) * sin(2 * $latitude) +
797 9
            (15 / 256 * $e4 + 45 / 1024 * $e ** 6 + 525 / 16384 * $e ** 8 + 1575 / 65536 * $e10 + 155925 / 8388608 * $e12 + 495495 / 33554432 * $e14) * sin(4 * $latitude) +
798 9
            (-35 / 3072 * $e6 - 175 / 12288 * $e8 - 3675 / 262144 * $e10 - 13475 / 1048576 * $e12 - 385385 / 33554432 * $e14) * sin(6 * $latitude) +
799 9
            (315 / 131072 * $e8 + 2205 / 524288 * $e10 + 43659 / 8388608 * $e12 + 189189 / 33554432 * $e14) * sin(8 * $latitude) +
800 9
            (-693 / 1310720 * $e10 - 6537 / 5242880 * $e12 - 297297 / 167772160 * $e14) * sin(10 * $latitude) +
801 9
            (1001 / 8388608 * $e12 + 11011 / 33554432 * $e14) * sin(12 * $latitude) +
802 9
            (-6435 / 234881024 * $e ** 14) * sin(14 * $latitude)
803
        );
804
805 9
        $easting = $falseEasting->asMetres()->getValue() + $nu1 * cos($latitudeFirstParallel) * $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue();
806 9
        $northing = $falseNorthing->asMetres()->getValue() + $M;
807
808 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
809
    }
810
811
    /**
812
     * Guam Projection
813
     * Simplified form of Oblique Azimuthal Equidistant projection method.
814
     */
815 9
    public function guamProjection(
816
        Projected $to,
817
        Angle $latitudeOfNaturalOrigin,
818
        Angle $longitudeOfNaturalOrigin,
819
        Length $falseEasting,
820
        Length $falseNorthing
821
    ): ProjectedPoint {
822 9
        $latitude = $this->latitude->asRadians()->getValue();
823 9
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
824 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
825 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
826 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
827 9
        $e4 = $e ** 4;
828 9
        $e6 = $e ** 6;
829
830 9
        $M = $a * ((1 - $e2 / 4 - 3 * $e4 / 64 - 5 * $e6 / 256) * $latitude - (3 * $e2 / 8 + 3 * $e4 / 32 + 45 * $e6 / 1024) * sin(2 * $latitude) + (15 * $e4 / 256 + 45 * $e6 / 1024) * sin(4 * $latitude) - (35 * $e6 / 3072) * sin(6 * $latitude));
831 9
        $MO = $a * ((1 - $e2 / 4 - 3 * $e4 / 64 - 5 * $e6 / 256) * $latitudeOrigin - (3 * $e2 / 8 + 3 * $e4 / 32 + 45 * $e6 / 1024) * sin(2 * $latitudeOrigin) + (15 * $e4 / 256 + 45 * $e6 / 1024) * sin(4 * $latitudeOrigin) - (35 * $e6 / 3072) * sin(6 * $latitudeOrigin));
832 9
        $x = ($a * $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue() * cos($latitude)) / sqrt(1 - $e2 * sin($latitude) ** 2);
833
834 9
        $easting = $falseEasting->asMetres()->getValue() + $x;
835 9
        $northing = $falseNorthing->asMetres()->getValue() + $M - $MO + ($x ** 2 * tan($latitude) * sqrt(1 - $e2 * sin($latitude) ** 2) / (2 * $a));
836
837 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
838
    }
839
840
    /**
841
     * Krovak.
842
     */
843 36
    public function krovak(
844
        Projected $to,
845
        Angle $latitudeOfProjectionCentre,
846
        Angle $longitudeOfOrigin,
847
        Angle $coLatitudeOfConeAxis,
848
        Angle $latitudeOfPseudoStandardParallel,
849
        Scale $scaleFactorOnPseudoStandardParallel,
850
        Length $falseEasting,
851
        Length $falseNorthing
852
    ): ProjectedPoint {
853 36
        $longitudeOffset = $to->getDatum()->getPrimeMeridian()->getGreenwichLongitude()->asRadians()->getValue() - $this->getCRS()->getDatum()->getPrimeMeridian()->getGreenwichLongitude()->asRadians()->getValue();
854 36
        $latitude = $this->latitude->asRadians()->getValue();
855 36
        $longitude = $this->longitude->asRadians()->getValue() - $longitudeOffset;
856 36
        $latitudeC = $latitudeOfProjectionCentre->asRadians()->getValue();
857 36
        $longitudeO = $longitudeOfOrigin->asRadians()->getValue();
858 36
        $alphaC = $coLatitudeOfConeAxis->asRadians()->getValue();
859 36
        $latitudeP = $latitudeOfPseudoStandardParallel->asRadians()->getValue();
860 36
        $kP = $scaleFactorOnPseudoStandardParallel->asUnity()->getValue();
861 36
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
862 36
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
863 36
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
864
865 36
        $A = $a * sqrt(1 - $e2) / (1 - $e2 * sin($latitudeC) ** 2);
866 36
        $B = sqrt(1 + $e2 * cos($latitudeC) ** 4 / (1 - $e2));
867 36
        $upsilonO = self::asin(sin($latitudeC) / $B);
868 36
        $tO = tan(M_PI / 4 + $upsilonO / 2) * ((1 + $e * sin($latitudeC)) / (1 - $e * sin($latitudeC))) ** ($e * $B / 2) / (tan(M_PI / 4 + $latitudeC / 2) ** $B);
869 36
        $n = sin($latitudeP);
870 36
        $rO = $kP * $A / tan($latitudeP);
871
872 36
        $U = 2 * (atan($tO * tan($latitude / 2 + M_PI / 4) ** $B / ((1 + $e * sin($latitude)) / (1 - $e * sin($latitude))) ** ($e * $B / 2)) - M_PI / 4);
873 36
        $V = $B * ($longitudeO - $longitude);
874 36
        $T = self::asin(cos($alphaC) * sin($U) + sin($alphaC) * cos($U) * cos($V));
875 36
        $D = atan2(cos($U) * sin($V) / cos($T), ((cos($alphaC) * sin($T) - sin($U)) / (sin($alphaC) * cos($T))));
876 36
        $theta = $n * $D;
877 36
        $r = $rO * tan(M_PI / 4 + $latitudeP / 2) ** $n / tan($T / 2 + M_PI / 4) ** $n;
878 36
        $X = $r * cos($theta);
879 36
        $Y = $r * sin($theta);
880
881 36
        $westing = $Y + $falseEasting->asMetres()->getValue();
882 36
        $southing = $X + $falseNorthing->asMetres()->getValue();
883
884 36
        return ProjectedPoint::create(new Metre(-$westing), new Metre(-$southing), new Metre($westing), new Metre($southing), $to, $this->epoch);
885
    }
886
887
    /**
888
     * Krovak Modified
889
     * Incorporates a polynomial transformation which is defined to be exact and for practical purposes is considered
890
     * to be a map projection.
891
     */
892 18
    public function krovakModified(
893
        Projected $to,
894
        Angle $latitudeOfProjectionCentre,
895
        Angle $longitudeOfOrigin,
896
        Angle $coLatitudeOfConeAxis,
897
        Angle $latitudeOfPseudoStandardParallel,
898
        Scale $scaleFactorOnPseudoStandardParallel,
899
        Length $falseEasting,
900
        Length $falseNorthing,
901
        Length $ordinate1OfEvaluationPoint,
902
        Length $ordinate2OfEvaluationPoint,
903
        Coefficient $C1,
904
        Coefficient $C2,
905
        Coefficient $C3,
906
        Coefficient $C4,
907
        Coefficient $C5,
908
        Coefficient $C6,
909
        Coefficient $C7,
910
        Coefficient $C8,
911
        Coefficient $C9,
912
        Coefficient $C10
913
    ): ProjectedPoint {
914 18
        $asKrovak = $this->krovak($to, $latitudeOfProjectionCentre, $longitudeOfOrigin, $coLatitudeOfConeAxis, $latitudeOfPseudoStandardParallel, $scaleFactorOnPseudoStandardParallel, new Metre(0), new Metre(0));
915
916 18
        $westing = $asKrovak->getWesting()->asMetres()->getValue();
917 18
        $southing = $asKrovak->getSouthing()->asMetres()->getValue();
918 18
        $c1 = $C1->asUnity()->getValue();
919 18
        $c2 = $C2->asUnity()->getValue();
920 18
        $c3 = $C3->asUnity()->getValue();
921 18
        $c4 = $C4->asUnity()->getValue();
922 18
        $c5 = $C5->asUnity()->getValue();
923 18
        $c6 = $C6->asUnity()->getValue();
924 18
        $c7 = $C7->asUnity()->getValue();
925 18
        $c8 = $C8->asUnity()->getValue();
926 18
        $c9 = $C9->asUnity()->getValue();
927 18
        $c10 = $C10->asUnity()->getValue();
928
929 18
        $Xr = $southing - $ordinate1OfEvaluationPoint->asMetres()->getValue();
930 18
        $Yr = $westing - $ordinate2OfEvaluationPoint->asMetres()->getValue();
931
932 18
        $dX = $c1 + $c3 * $Xr - $c4 * $Yr - 2 * $c6 * $Xr * $Yr + $c5 * ($Xr ** 2 - $Yr ** 2) + $c7 * $Xr * ($Xr ** 2 - 3 * $Yr ** 2) - $c8 * $Yr * (3 * $Xr ** 2 - $Yr ** 2) + 4 * $c9 * $Xr * $Yr * ($Xr ** 2 - $Yr ** 2) + $c10 * ($Xr ** 4 + $Yr ** 4 - 6 * $Xr ** 2 * $Yr ** 2);
933 18
        $dY = $c2 + $c3 * $Yr + $c4 * $Xr + 2 * $c5 * $Xr * $Yr + $c6 * ($Xr ** 2 - $Yr ** 2) + $c8 * $Xr * ($Xr ** 2 - 3 * $Yr ** 2) + $c7 * $Yr * (3 * $Xr ** 2 - $Yr ** 2) - 4 * $c10 * $Xr * $Yr * ($Xr ** 2 - $Yr ** 2) + $c9 * ($Xr ** 4 + $Yr ** 4 - 6 * $Xr ** 2 * $Yr ** 2);
934
935 18
        $westing += $falseEasting->asMetres()->getValue() - $dY;
936 18
        $southing += $falseNorthing->asMetres()->getValue() - $dX;
937
938 18
        return ProjectedPoint::create(new Metre(-$westing), new Metre(-$southing), new Metre($westing), new Metre($southing), $to, $this->epoch);
939
    }
940
941
    /**
942
     * Lambert Azimuthal Equal Area
943
     * This is the ellipsoidal form of the projection.
944
     */
945 9
    public function lambertAzimuthalEqualArea(
946
        Projected $to,
947
        Angle $latitudeOfNaturalOrigin,
948
        Angle $longitudeOfNaturalOrigin,
949
        Length $falseEasting,
950
        Length $falseNorthing
951
    ): ProjectedPoint {
952 9
        $latitude = $this->latitude->asRadians()->getValue();
953 9
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
954 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
955 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
956 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
957
958 9
        $q = (1 - $e2) * ((sin($latitude) / (1 - $e2 * sin($latitude) ** 2)) - ((1 / (2 * $e)) * log((1 - $e * sin($latitude)) / (1 + $e * sin($latitude)))));
959 9
        $qO = (1 - $e2) * ((sin($latitudeOrigin) / (1 - $e2 * sin($latitudeOrigin) ** 2)) - ((1 / (2 * $e)) * log((1 - $e * sin($latitudeOrigin)) / (1 + $e * sin($latitudeOrigin)))));
960 9
        $qP = (1 - $e2) * ((1 / (1 - $e2)) - ((1 / (2 * $e)) * log((1 - $e) / (1 + $e))));
961 9
        $beta = self::asin($q / $qP);
962 9
        $betaO = self::asin($qO / $qP);
963 9
        $Rq = $a * sqrt($qP / 2);
964 9
        $B = $Rq * sqrt(2 / (1 + sin($betaO) * sin($beta) + (cos($betaO) * cos($beta) * cos($this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue()))));
965 9
        $D = $a * (cos($latitudeOrigin) / sqrt(1 - $e2 * sin($latitudeOrigin) ** 2)) / ($Rq * cos($betaO));
966
967 9
        $easting = $falseEasting->asMetres()->getValue() + (($B * $D) * (cos($beta) * sin($this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue())));
968 9
        $northing = $falseNorthing->asMetres()->getValue() + ($B / $D) * ((cos($betaO) * sin($beta)) - (sin($betaO) * cos($beta) * cos($this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue())));
969
970 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
971
    }
972
973
    /**
974
     * Lambert Azimuthal Equal Area (Spherical)
975
     * This is the spherical form of the projection.  See coordinate operation method Lambert Azimuthal Equal Area
976
     * (code 9820) for ellipsoidal form.  Differences of several tens of metres result from comparison of the two
977
     * methods.
978
     */
979 9
    public function lambertAzimuthalEqualAreaSpherical(
980
        Projected $to,
981
        Angle $latitudeOfNaturalOrigin,
982
        Angle $longitudeOfNaturalOrigin,
983
        Length $falseEasting,
984
        Length $falseNorthing
985
    ): ProjectedPoint {
986 9
        $latitude = $this->latitude->asRadians()->getValue();
987 9
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
988 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
989
990 9
        $k = sqrt(2 / (1 + sin($latitudeOrigin) * sin($latitude) + cos($latitudeOrigin) * cos($latitude) * cos($this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue())));
991
992 9
        $easting = $falseEasting->asMetres()->getValue() + ($a * $k * cos($latitude) * sin($this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue()));
993 9
        $northing = $falseNorthing->asMetres()->getValue() + ($a * $k * (cos($latitudeOrigin) * sin($latitude) - sin($latitudeOrigin) * cos($latitude) * cos($this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue())));
994
995 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
996
    }
997
998
    /**
999
     * Lambert Conic Conformal (1SP).
1000
     */
1001 9
    public function lambertConicConformal1SP(
1002
        Projected $to,
1003
        Angle $latitudeOfNaturalOrigin,
1004
        Angle $longitudeOfNaturalOrigin,
1005
        Scale $scaleFactorAtNaturalOrigin,
1006
        Length $falseEasting,
1007
        Length $falseNorthing
1008
    ): ProjectedPoint {
1009 9
        $latitude = $this->latitude->asRadians()->getValue();
1010 9
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
1011 9
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
1012 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1013 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1014 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1015
1016 9
        $mO = cos($latitudeOrigin) / sqrt(1 - $e2 * sin($latitudeOrigin) ** 2);
1017 9
        $tO = tan(M_PI / 4 - $latitudeOrigin / 2) / ((1 - $e * sin($latitudeOrigin)) / (1 + $e * sin($latitudeOrigin))) ** ($e / 2);
1018 9
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1019 9
        $n = sin($latitudeOrigin);
1020 9
        $F = $mO / ($n * $tO ** $n);
1021 9
        $rO = $a * $F * $tO ** $n * $kO;
1022 9
        $r = $a * $F * $t ** $n * $kO;
1023 9
        $theta = $n * $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue();
1024
1025 9
        $easting = $falseEasting->asMetres()->getValue() + $r * sin($theta);
1026 9
        $northing = $falseNorthing->asMetres()->getValue() + $rO - $r * cos($theta);
1027
1028 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1029
    }
1030
1031
    /**
1032
     * Lambert Conic Conformal (1SP) Variant B.
1033
     */
1034
    public function lambertConicConformal1SPVariantB(
1035
        Projected $to,
1036
        Angle $latitudeOfNaturalOrigin,
1037
        Scale $scaleFactorAtNaturalOrigin,
1038
        Angle $latitudeOfFalseOrigin,
1039
        Angle $longitudeOfFalseOrigin,
1040
        Length $eastingAtFalseOrigin,
1041
        Length $northingAtFalseOrigin
1042
    ): ProjectedPoint {
1043
        $latitude = $this->latitude->asRadians()->getValue();
1044
        $latitudeNaturalOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
1045
        $latitudeFalseOrigin = $latitudeOfFalseOrigin->asRadians()->getValue();
1046
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
1047
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1048
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1049
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1050
1051
        $mO = cos($latitudeNaturalOrigin) / sqrt(1 - $e2 * sin($latitudeNaturalOrigin) ** 2);
1052
        $tO = tan(M_PI / 4 - $latitudeNaturalOrigin / 2) / ((1 - $e * sin($latitudeNaturalOrigin)) / (1 + $e * sin($latitudeNaturalOrigin))) ** ($e / 2);
1053
        $tF = tan(M_PI / 4 - $latitudeFalseOrigin / 2) / ((1 - $e * sin($latitudeFalseOrigin)) / (1 + $e * sin($latitudeFalseOrigin))) ** ($e / 2);
1054
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1055
        $n = sin($latitudeNaturalOrigin);
1056
        $F = $mO / ($n * $tO ** $n);
1057
        $rF = $a * $F * $tF ** $n * $kO;
1058
        $r = $a * $F * $t ** $n * $kO;
1059
        $theta = $n * $this->normaliseLongitude($this->longitude->subtract($longitudeOfFalseOrigin))->asRadians()->getValue();
1060
1061
        $easting = $eastingAtFalseOrigin->asMetres()->getValue() + $r * sin($theta);
1062
        $northing = $northingAtFalseOrigin->asMetres()->getValue() + $rF - $r * cos($theta);
1063
1064
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1065
    }
1066
1067
    /**
1068
     * Lambert Conic Conformal (2SP Belgium)
1069
     * In 2000 this modification was replaced through use of the regular Lambert Conic Conformal (2SP) method [9802]
1070
     * with appropriately modified parameter values.
1071
     */
1072 9
    public function lambertConicConformal2SPBelgium(
1073
        Projected $to,
1074
        Angle $latitudeOfFalseOrigin,
1075
        Angle $longitudeOfFalseOrigin,
1076
        Angle $latitudeOf1stStandardParallel,
1077
        Angle $latitudeOf2ndStandardParallel,
1078
        Length $eastingAtFalseOrigin,
1079
        Length $northingAtFalseOrigin
1080
    ): ProjectedPoint {
1081 9
        $latitude = $this->latitude->asRadians()->getValue();
1082 9
        $phiF = $latitudeOfFalseOrigin->asRadians()->getValue();
1083 9
        $phi1 = $latitudeOf1stStandardParallel->asRadians()->getValue();
1084 9
        $phi2 = $latitudeOf2ndStandardParallel->asRadians()->getValue();
1085 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1086 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1087 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1088
1089 9
        $m1 = cos($phi1) / sqrt(1 - $e2 * sin($phi1) ** 2);
1090 9
        $m2 = cos($phi2) / sqrt(1 - $e2 * sin($phi2) ** 2);
1091 9
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1092 9
        $t1 = tan(M_PI / 4 - $phi1 / 2) / ((1 - $e * sin($phi1)) / (1 + $e * sin($phi1))) ** ($e / 2);
1093 9
        $t2 = tan(M_PI / 4 - $phi2 / 2) / ((1 - $e * sin($phi2)) / (1 + $e * sin($phi2))) ** ($e / 2);
1094 9
        $tF = tan(M_PI / 4 - $phiF / 2) / ((1 - $e * sin($phiF)) / (1 + $e * sin($phiF))) ** ($e / 2);
1095 9
        $n = (log($m1) - log($m2)) / (log($t1) - log($t2));
1096 9
        $F = $m1 / ($n * $t1 ** $n);
1097 9
        $r = $a * $F * $t ** $n;
1098 9
        $rF = $a * $F * $tF ** $n;
1099 9
        if (is_nan($rF)) {
1100 9
            $rF = 0;
1101
        }
1102 9
        $theta = ($n * $this->normaliseLongitude($this->longitude->subtract($longitudeOfFalseOrigin))->asRadians()->getValue()) - (new ArcSecond(29.2985))->asRadians()->getValue();
1103
1104 9
        $easting = $eastingAtFalseOrigin->asMetres()->getValue() + $r * sin($theta);
1105 9
        $northing = $northingAtFalseOrigin->asMetres()->getValue() + $rF - $r * cos($theta);
1106
1107 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1108
    }
1109
1110
    /**
1111
     * Lambert Conic Conformal (2SP Michigan).
1112
     */
1113 9
    public function lambertConicConformal2SPMichigan(
1114
        Projected $to,
1115
        Angle $latitudeOfFalseOrigin,
1116
        Angle $longitudeOfFalseOrigin,
1117
        Angle $latitudeOf1stStandardParallel,
1118
        Angle $latitudeOf2ndStandardParallel,
1119
        Length $eastingAtFalseOrigin,
1120
        Length $northingAtFalseOrigin,
1121
        Scale $ellipsoidScalingFactor
1122
    ): ProjectedPoint {
1123 9
        $latitude = $this->latitude->asRadians()->getValue();
1124 9
        $phiF = $latitudeOfFalseOrigin->asRadians()->getValue();
1125 9
        $phi1 = $latitudeOf1stStandardParallel->asRadians()->getValue();
1126 9
        $phi2 = $latitudeOf2ndStandardParallel->asRadians()->getValue();
1127 9
        $K = $ellipsoidScalingFactor->asUnity()->getValue();
1128 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1129 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1130 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1131
1132 9
        $m1 = cos($phi1) / sqrt(1 - $e2 * sin($phi1) ** 2);
1133 9
        $m2 = cos($phi2) / sqrt(1 - $e2 * sin($phi2) ** 2);
1134 9
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1135 9
        $t1 = tan(M_PI / 4 - $phi1 / 2) / ((1 - $e * sin($phi1)) / (1 + $e * sin($phi1))) ** ($e / 2);
1136 9
        $t2 = tan(M_PI / 4 - $phi2 / 2) / ((1 - $e * sin($phi2)) / (1 + $e * sin($phi2))) ** ($e / 2);
1137 9
        $tF = tan(M_PI / 4 - $phiF / 2) / ((1 - $e * sin($phiF)) / (1 + $e * sin($phiF))) ** ($e / 2);
1138 9
        $n = (log($m1) - log($m2)) / (log($t1) - log($t2));
1139 9
        $F = $m1 / ($n * $t1 ** $n);
1140 9
        $r = $a * $K * $F * $t ** $n;
1141 9
        $rF = $a * $K * $F * $tF ** $n;
1142 9
        $theta = $n * $this->normaliseLongitude($this->longitude->subtract($longitudeOfFalseOrigin))->asRadians()->getValue();
1143
1144 9
        $easting = $eastingAtFalseOrigin->asMetres()->getValue() + $r * sin($theta);
1145 9
        $northing = $northingAtFalseOrigin->asMetres()->getValue() + $rF - $r * cos($theta);
1146
1147 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1148
    }
1149
1150
    /**
1151
     * Lambert Conic Conformal (2SP).
1152
     */
1153 9
    public function lambertConicConformal2SP(
1154
        Projected $to,
1155
        Angle $latitudeOfFalseOrigin,
1156
        Angle $longitudeOfFalseOrigin,
1157
        Angle $latitudeOf1stStandardParallel,
1158
        Angle $latitudeOf2ndStandardParallel,
1159
        Length $eastingAtFalseOrigin,
1160
        Length $northingAtFalseOrigin
1161
    ): ProjectedPoint {
1162 9
        $latitude = $this->latitude->asRadians()->getValue();
1163 9
        $phiF = $latitudeOfFalseOrigin->asRadians()->getValue();
1164 9
        $phi1 = $latitudeOf1stStandardParallel->asRadians()->getValue();
1165 9
        $phi2 = $latitudeOf2ndStandardParallel->asRadians()->getValue();
1166 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1167 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1168 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1169
1170 9
        $m1 = cos($phi1) / sqrt(1 - $e2 * sin($phi1) ** 2);
1171 9
        $m2 = cos($phi2) / sqrt(1 - $e2 * sin($phi2) ** 2);
1172 9
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1173 9
        $t1 = tan(M_PI / 4 - $phi1 / 2) / ((1 - $e * sin($phi1)) / (1 + $e * sin($phi1))) ** ($e / 2);
1174 9
        $t2 = tan(M_PI / 4 - $phi2 / 2) / ((1 - $e * sin($phi2)) / (1 + $e * sin($phi2))) ** ($e / 2);
1175 9
        $tF = tan(M_PI / 4 - $phiF / 2) / ((1 - $e * sin($phiF)) / (1 + $e * sin($phiF))) ** ($e / 2);
1176 9
        $n = (log($m1) - log($m2)) / (log($t1) - log($t2));
1177 9
        $F = $m1 / ($n * $t1 ** $n);
1178 9
        $r = $a * $F * $t ** $n;
1179 9
        $rF = $a * $F * $tF ** $n;
1180 9
        $theta = $n * $this->normaliseLongitude($this->longitude->subtract($longitudeOfFalseOrigin))->asRadians()->getValue();
1181
1182 9
        $easting = $eastingAtFalseOrigin->asMetres()->getValue() + $r * sin($theta);
1183 9
        $northing = $northingAtFalseOrigin->asMetres()->getValue() + $rF - $r * cos($theta);
1184
1185 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1186
    }
1187
1188
    /**
1189
     * Lambert Conic Conformal (West Orientated).
1190
     */
1191
    public function lambertConicConformalWestOrientated(
1192
        Projected $to,
1193
        Angle $latitudeOfNaturalOrigin,
1194
        Angle $longitudeOfNaturalOrigin,
1195
        Scale $scaleFactorAtNaturalOrigin,
1196
        Length $falseEasting,
1197
        Length $falseNorthing
1198
    ): ProjectedPoint {
1199
        $latitude = $this->latitude->asRadians()->getValue();
1200
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
1201
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
1202
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1203
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1204
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1205
1206
        $mO = cos($latitudeOrigin) / sqrt(1 - $e2 * sin($latitudeOrigin) ** 2);
1207
        $tO = tan(M_PI / 4 - $latitudeOrigin / 2) / ((1 - $e * sin($latitudeOrigin)) / (1 + $e * sin($latitudeOrigin))) ** ($e / 2);
1208
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1209
        $n = sin($latitudeOrigin);
1210
        $F = $mO / ($n * $tO ** $n);
1211
        $rO = $a * $F * $tO ** $n ** $kO;
1212
        $r = $a * $F * $t ** $n ** $kO;
1213
        $theta = $n * $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue();
1214
1215
        $westing = $falseEasting->asMetres()->getValue() - $r * sin($theta);
1216
        $northing = $falseNorthing->asMetres()->getValue() + $rO - $r * cos($theta);
1217
1218
        return ProjectedPoint::create(new Metre(-$westing), new Metre($northing), new Metre($westing), new Metre(-$northing), $to, $this->epoch);
1219
    }
1220
1221
    /**
1222
     * Lambert Conic Near-Conformal
1223
     * The Lambert Near-Conformal projection is derived from the Lambert Conformal Conic projection by truncating the
1224
     * series expansion of the projection formulae.
1225
     */
1226 9
    public function lambertConicNearConformal(
1227
        Projected $to,
1228
        Angle $latitudeOfNaturalOrigin,
1229
        Angle $longitudeOfNaturalOrigin,
1230
        Scale $scaleFactorAtNaturalOrigin,
1231
        Length $falseEasting,
1232
        Length $falseNorthing
1233
    ): ProjectedPoint {
1234 9
        $latitude = $this->latitude->asRadians()->getValue();
1235 9
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
1236 9
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
1237 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1238 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1239 9
        $f = $this->crs->getDatum()->getEllipsoid()->getInverseFlattening();
1240
1241 9
        $n = $f / (2 - $f);
1242 9
        $rhoO = $a * (1 - $e2) / (1 - $e2 * sin($latitudeOrigin) ** 2) ** (3 / 2);
1243 9
        $nuO = $a / sqrt(1 - $e2 * (sin($latitudeOrigin) ** 2));
1244 9
        $A = 1 / (6 * $rhoO * $nuO);
1245 9
        $APrime = $a * (1 - $n + 5 * ($n ** 2 - $n ** 3) / 4 + 81 * ($n ** 4 - $n ** 5) / 64);
1246 9
        $BPrime = 3 * $a * ($n - $n ** 2 + 7 * ($n ** 3 - $n ** 4) / 8 + 55 * $n ** 5 / 64) / 2;
1247 9
        $CPrime = 15 * $a * ($n ** 2 - $n ** 3 + 3 * ($n ** 4 - $n ** 5) / 4) / 16;
1248 9
        $DPrime = 35 * $a * ($n ** 3 - $n ** 4 + 11 * $n ** 5 / 16) / 48;
1249 9
        $EPrime = 315 * $a * ($n ** 4 - $n ** 5) / 512;
1250 9
        $rO = $kO * $nuO / tan($latitudeOrigin);
1251 9
        $sO = $APrime * $latitudeOrigin - $BPrime * sin(2 * $latitudeOrigin) + $CPrime * sin(4 * $latitudeOrigin) - $DPrime * sin(6 * $latitudeOrigin) + $EPrime * sin(8 * $latitudeOrigin);
1252 9
        $s = $APrime * $latitude - $BPrime * sin(2 * $latitude) + $CPrime * sin(4 * $latitude) - $DPrime * sin(6 * $latitude) + $EPrime * sin(8 * $latitude);
1253 9
        $m = $s - $sO;
1254 9
        $M = $kO * ($m + $A * $m ** 3);
1255 9
        $r = $rO - $M;
1256 9
        $theta = $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue() * sin($latitudeOrigin);
1257
1258 9
        $easting = $falseEasting->asMetres()->getValue() + $r * sin($theta);
1259 9
        $northing = $falseNorthing->asMetres()->getValue() + $M + $r * sin($theta) * tan($theta / 2);
1260
1261 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1262
    }
1263
1264
    /**
1265
     * Lambert Cylindrical Equal Area
1266
     * This is the ellipsoidal form of the projection.
1267
     */
1268 9
    public function lambertCylindricalEqualArea(
1269
        Projected $to,
1270
        Angle $latitudeOf1stStandardParallel,
1271
        Angle $longitudeOfNaturalOrigin,
1272
        Length $falseEasting,
1273
        Length $falseNorthing
1274
    ): ProjectedPoint {
1275 9
        $latitude = $this->latitude->asRadians()->getValue();
1276 9
        $latitudeFirstParallel = $latitudeOf1stStandardParallel->asRadians()->getValue();
1277 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1278 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1279 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1280
1281 9
        $k = cos($latitudeFirstParallel) / sqrt(1 - $e2 * sin($latitudeFirstParallel) ** 2);
1282 9
        $q = (1 - $e2) * ((sin($latitude) / (1 - $e2 * sin($latitude) ** 2)) - (1 / (2 * $e)) * log((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))));
1283
1284 9
        $x = $a * $k * $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue();
1285 9
        $y = $a * $q / (2 * $k);
1286
1287 9
        $easting = $falseEasting->asMetres()->getValue() + $x;
1288 9
        $northing = $falseNorthing->asMetres()->getValue() + $y;
1289
1290 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1291
    }
1292
1293
    /**
1294
     * Modified Azimuthal Equidistant
1295
     * Modified form of Oblique Azimuthal Equidistant projection method developed for Polynesian islands. For the
1296
     * distances over which these projections are used (under 800km) this modification introduces no significant error.
1297
     */
1298 9
    public function modifiedAzimuthalEquidistant(
1299
        Projected $to,
1300
        Angle $latitudeOfNaturalOrigin,
1301
        Angle $longitudeOfNaturalOrigin,
1302
        Length $falseEasting,
1303
        Length $falseNorthing
1304
    ): ProjectedPoint {
1305 9
        $latitude = $this->latitude->asRadians()->getValue();
1306 9
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
1307 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1308 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1309 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1310
1311 9
        $nuO = $a / sqrt(1 - $e2 * sin($latitudeOrigin) ** 2);
1312 9
        $nu = $a / sqrt(1 - $e2 * sin($latitude) ** 2);
1313 9
        $psi = atan((1 - $e2) * tan($latitude) + ($e2 * $nuO * sin($latitudeOrigin)) / ($nu * cos($latitude)));
1314 9
        $alpha = atan2(sin($this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue()), (cos($latitudeOrigin) * tan($psi) - sin($latitudeOrigin) * cos($this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue())));
1315 9
        $G = $e * sin($latitudeOrigin) / sqrt(1 - $e2);
1316 9
        $H = $e * cos($latitudeOrigin) * cos($alpha) / sqrt(1 - $e2);
1317
1318 9
        if (sin($alpha) === 0.0) {
1319
            $s = self::asin(cos($latitudeOrigin) * sin($psi) - sin($latitudeOrigin) * cos($alpha)) * cos($alpha) / abs(cos($alpha));
1320
        } else {
1321 9
            $s = self::asin(sin($this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue()) * cos($psi) / sin($alpha));
1322
        }
1323
1324 9
        $c = $nuO * $s * ((1 - $s ** 2 * $H ** 2 * (1 - $H ** 2) / 6) + (($s ** 3 / 8) * $G * $H * (1 - 2 * $H ** 2)) + ($s ** 4 / 120) * ($H ** 2 * (4 - 7 * $H ** 2) - 3 * $G ** 2 * (1 - 7 * $H ** 2)) - (($s ** 5 / 48) * $G * $H));
1325
1326 9
        $easting = $falseEasting->asMetres()->getValue() + $c * sin($alpha);
1327 9
        $northing = $falseNorthing->asMetres()->getValue() + $c * cos($alpha);
1328
1329 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1330
    }
1331
1332
    /**
1333
     * Oblique Stereographic
1334
     * This is not the same as the projection method of the same name in USGS Professional Paper no. 1395, "Map
1335
     * Projections - A Working Manual" by John P. Snyder.
1336
     */
1337 9
    public function obliqueStereographic(
1338
        Projected $to,
1339
        Angle $latitudeOfNaturalOrigin,
1340
        Angle $longitudeOfNaturalOrigin,
1341
        Scale $scaleFactorAtNaturalOrigin,
1342
        Length $falseEasting,
1343
        Length $falseNorthing
1344
    ): ProjectedPoint {
1345 9
        $latitude = $this->latitude->asRadians()->getValue();
1346 9
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
1347 9
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
1348 9
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
1349 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1350 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1351 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1352
1353 9
        $rhoOrigin = $a * (1 - $e2) / (1 - $e2 * sin($latitudeOrigin) ** 2) ** (3 / 2);
1354 9
        $nuOrigin = $a / sqrt(1 - $e2 * (sin($latitudeOrigin) ** 2));
1355 9
        $R = sqrt($rhoOrigin * $nuOrigin);
1356
1357 9
        $n = sqrt(1 + ($e2 * cos($latitudeOrigin) ** 4 / (1 - $e2)));
1358 9
        $S1 = (1 + sin($latitudeOrigin)) / (1 - sin($latitudeOrigin));
1359 9
        $S2 = (1 - $e * sin($latitudeOrigin)) / (1 + $e * sin($latitudeOrigin));
1360 9
        $w1 = ($S1 * ($S2 ** $e)) ** $n;
1361 9
        $c = (($n + sin($latitudeOrigin)) * (1 - ($w1 - 1) / ($w1 + 1))) / (($n - sin($latitudeOrigin)) * (1 + ($w1 - 1) / ($w1 + 1)));
1362 9
        $w2 = $c * $w1;
1363 9
        $chiOrigin = self::asin(($w2 - 1) / ($w2 + 1));
1364
1365 9
        $lambda = $n * $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue() + $longitudeOrigin;
1366
1367 9
        $Sa = (1 + sin($latitude)) / (1 - sin($latitude));
1368 9
        $Sb = (1 - $e * sin($latitude)) / (1 + $e * sin($latitude));
1369 9
        $w = $c * ($Sa * ($Sb ** $e)) ** $n;
1370 9
        $chi = self::asin(($w - 1) / ($w + 1));
1371
1372 9
        $B = (1 + sin($chi) * sin($chiOrigin) + cos($chi) * cos($chiOrigin) * cos($lambda - $longitudeOrigin));
1373
1374 9
        $easting = $falseEasting->asMetres()->getValue() + 2 * $R * $kO * cos($chi) * sin($lambda - $longitudeOrigin) / $B;
1375 9
        $northing = $falseNorthing->asMetres()->getValue() + 2 * $R * $kO * (sin($chi) * cos($chiOrigin) - cos($chi) * sin($chiOrigin) * cos($lambda - $longitudeOrigin)) / $B;
1376
1377 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1378
    }
1379
1380
    /**
1381
     * Polar Stereographic (variant A)
1382
     * Latitude of natural origin must be either 90 degrees or -90 degrees (or equivalent in alternative angle unit).
1383
     */
1384 9
    public function polarStereographicVariantA(
1385
        Projected $to,
1386
        Angle $latitudeOfNaturalOrigin,
1387
        Angle $longitudeOfNaturalOrigin,
1388
        Scale $scaleFactorAtNaturalOrigin,
1389
        Length $falseEasting,
1390
        Length $falseNorthing
1391
    ): ProjectedPoint {
1392 9
        $latitude = $this->latitude->asRadians()->getValue();
1393 9
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
1394 9
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
1395 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1396 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1397
1398 9
        if ($latitudeOrigin < 0) {
1399
            $t = tan(M_PI / 4 + $latitude / 2) / (((1 + $e * sin($latitude)) / (1 - $e * sin($latitude))) ** ($e / 2));
1400
        } else {
1401 9
            $t = tan(M_PI / 4 - $latitude / 2) * (((1 + $e * sin($latitude)) / (1 - $e * sin($latitude))) ** ($e / 2));
1402
        }
1403 9
        $rho = 2 * $a * $kO * $t / sqrt((1 + $e) ** (1 + $e) * (1 - $e) ** (1 - $e));
1404
1405 9
        $theta = $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue();
1406 9
        $dE = $rho * sin($theta);
1407 9
        $dN = $rho * cos($theta);
1408
1409 9
        $easting = $falseEasting->asMetres()->getValue() + $dE;
1410 9
        if ($latitudeOrigin < 0) {
1411
            $northing = $falseNorthing->asMetres()->getValue() + $dN;
1412
        } else {
1413 9
            $northing = $falseNorthing->asMetres()->getValue() - $dN;
1414
        }
1415
1416 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1417
    }
1418
1419
    /**
1420
     * Polar Stereographic (variant B).
1421
     */
1422 9
    public function polarStereographicVariantB(
1423
        Projected $to,
1424
        Angle $latitudeOfStandardParallel,
1425
        Angle $longitudeOfOrigin,
1426
        Length $falseEasting,
1427
        Length $falseNorthing
1428
    ): ProjectedPoint {
1429 9
        $latitude = $this->latitude->asRadians()->getValue();
1430 9
        $firstStandardParallel = $latitudeOfStandardParallel->asRadians()->getValue();
1431 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1432 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1433 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1434
1435 9
        if ($firstStandardParallel < 0) {
1436 9
            $tF = tan(M_PI / 4 + $firstStandardParallel / 2) / (((1 + $e * sin($firstStandardParallel)) / (1 - $e * sin($firstStandardParallel))) ** ($e / 2));
1437 9
            $t = tan(M_PI / 4 + $latitude / 2) / (((1 + $e * sin($latitude)) / (1 - $e * sin($latitude))) ** ($e / 2));
1438
        } else {
1439
            $tF = tan(M_PI / 4 - $firstStandardParallel / 2) * (((1 + $e * sin($firstStandardParallel)) / (1 - $e * sin($firstStandardParallel))) ** ($e / 2));
1440
            $t = tan(M_PI / 4 - $latitude / 2) * (((1 + $e * sin($latitude)) / (1 - $e * sin($latitude))) ** ($e / 2));
1441
        }
1442 9
        $mF = cos($firstStandardParallel) / sqrt(1 - $e2 * sin($firstStandardParallel) ** 2);
1443 9
        $kO = $mF * sqrt((1 + $e) ** (1 + $e) * (1 - $e) ** (1 - $e)) / (2 * $tF);
1444
1445 9
        $rho = 2 * $a * $kO * $t / sqrt((1 + $e) ** (1 + $e) * (1 - $e) ** (1 - $e));
1446
1447 9
        $theta = $this->normaliseLongitude($this->longitude->subtract($longitudeOfOrigin))->asRadians()->getValue();
1448 9
        $dE = $rho * sin($theta);
1449 9
        $dN = $rho * cos($theta);
1450
1451 9
        $easting = $falseEasting->asMetres()->getValue() + $dE;
1452 9
        if ($firstStandardParallel < 0) {
1453 9
            $northing = $falseNorthing->asMetres()->getValue() + $dN;
1454
        } else {
1455
            $northing = $falseNorthing->asMetres()->getValue() - $dN;
1456
        }
1457
1458 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1459
    }
1460
1461
    /**
1462
     * Polar Stereographic (variant C).
1463
     */
1464 9
    public function polarStereographicVariantC(
1465
        Projected $to,
1466
        Angle $latitudeOfStandardParallel,
1467
        Angle $longitudeOfOrigin,
1468
        Length $eastingAtFalseOrigin,
1469
        Length $northingAtFalseOrigin
1470
    ): ProjectedPoint {
1471 9
        $latitude = $this->latitude->asRadians()->getValue();
1472 9
        $firstStandardParallel = $latitudeOfStandardParallel->asRadians()->getValue();
1473 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1474 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1475 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1476
1477 9
        if ($firstStandardParallel < 0) {
1478 9
            $tF = tan(M_PI / 4 + $firstStandardParallel / 2) / (((1 + $e * sin($firstStandardParallel)) / (1 - $e * sin($firstStandardParallel))) ** ($e / 2));
1479 9
            $t = tan(M_PI / 4 + $latitude / 2) / (((1 + $e * sin($latitude)) / (1 - $e * sin($latitude))) ** ($e / 2));
1480
        } else {
1481
            $tF = tan(M_PI / 4 - $firstStandardParallel / 2) * (((1 + $e * sin($firstStandardParallel)) / (1 - $e * sin($firstStandardParallel))) ** ($e / 2));
1482
            $t = tan(M_PI / 4 - $latitude / 2) * (((1 + $e * sin($latitude)) / (1 - $e * sin($latitude))) ** ($e / 2));
1483
        }
1484 9
        $mF = cos($firstStandardParallel) / sqrt(1 - $e2 * sin($firstStandardParallel) ** 2);
1485
1486 9
        $rhoF = $a * $mF;
1487 9
        $rho = $rhoF * $t / $tF;
1488
1489 9
        $theta = $this->normaliseLongitude($this->longitude->subtract($longitudeOfOrigin))->asRadians()->getValue();
1490 9
        $dE = $rho * sin($theta);
1491 9
        $dN = $rho * cos($theta);
1492
1493 9
        $easting = $eastingAtFalseOrigin->asMetres()->getValue() + $dE;
1494 9
        if ($firstStandardParallel < 0) {
1495 9
            $northing = $northingAtFalseOrigin->asMetres()->getValue() - $rhoF + $dN;
1496
        } else {
1497
            $northing = $northingAtFalseOrigin->asMetres()->getValue() + $rhoF - $dN;
1498
        }
1499
1500 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1501
    }
1502
1503
    /**
1504
     * Popular Visualisation Pseudo Mercator
1505
     * Applies spherical formulas to the ellipsoid. As such does not have the properties of a true Mercator projection.
1506
     */
1507 9
    public function popularVisualisationPseudoMercator(
1508
        Projected $to,
1509
        Angle $latitudeOfNaturalOrigin,
0 ignored issues
show
Unused Code introduced by
The parameter $latitudeOfNaturalOrigin is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1509
        /** @scrutinizer ignore-unused */ Angle $latitudeOfNaturalOrigin,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1510
        Angle $longitudeOfNaturalOrigin,
1511
        Length $falseEasting,
1512
        Length $falseNorthing
1513
    ): ProjectedPoint {
1514 9
        $latitude = $this->latitude->asRadians()->getValue();
1515 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1516
1517 9
        $easting = $falseEasting->asMetres()->getValue() + $a * ($this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue());
1518 9
        $northing = $falseNorthing->asMetres()->getValue() + $a * log(tan(M_PI / 4 + $latitude / 2));
1519
1520 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1521
    }
1522
1523
    /**
1524
     * Mercator (variant A)
1525
     * Note that in these formulas the parameter latitude of natural origin (latO) is not used. However for this
1526
     * Mercator (variant A) method the EPSG dataset includes this parameter, which must have a value of zero, for
1527
     * completeness in CRS labelling.
1528
     */
1529 18
    public function mercatorVariantA(
1530
        Projected $to,
1531
        Angle $latitudeOfNaturalOrigin,
0 ignored issues
show
Unused Code introduced by
The parameter $latitudeOfNaturalOrigin is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1531
        /** @scrutinizer ignore-unused */ Angle $latitudeOfNaturalOrigin,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1532
        Angle $longitudeOfNaturalOrigin,
1533
        Scale $scaleFactorAtNaturalOrigin,
1534
        Length $falseEasting,
1535
        Length $falseNorthing
1536
    ): ProjectedPoint {
1537 18
        $latitude = $this->latitude->asRadians()->getValue();
1538 18
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
1539
1540 18
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1541 18
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1542
1543 18
        $easting = $falseEasting->asMetres()->getValue() + $a * $kO * $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue();
1544 18
        $northing = $falseNorthing->asMetres()->getValue() + $a * $kO * log(tan(M_PI / 4 + $latitude / 2) * ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2));
1545
1546 18
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1547
    }
1548
1549
    /**
1550
     * Mercator (variant B)
1551
     * Used for most nautical charts.
1552
     */
1553 9
    public function mercatorVariantB(
1554
        Projected $to,
1555
        Angle $latitudeOf1stStandardParallel,
1556
        Angle $longitudeOfNaturalOrigin,
1557
        Length $falseEasting,
1558
        Length $falseNorthing
1559
    ): ProjectedPoint {
1560 9
        $latitude = $this->latitude->asRadians()->getValue();
1561 9
        $firstStandardParallel = $latitudeOf1stStandardParallel->asRadians()->getValue();
1562 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1563 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1564 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1565
1566 9
        $kO = cos($firstStandardParallel) / sqrt(1 - $e2 * sin($firstStandardParallel) ** 2);
1567
1568 9
        $easting = $falseEasting->asMetres()->getValue() + $a * $kO * $this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue();
1569 9
        $northing = $falseNorthing->asMetres()->getValue() + $a * $kO * log(tan(M_PI / 4 + $latitude / 2) * ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2));
1570
1571 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1572
    }
1573
1574
    /**
1575
     * Longitude rotation
1576
     * This transformation allows calculation of the longitude of a point in the target system by adding the parameter
1577
     * value to the longitude value of the point in the source system.
1578
     */
1579 9
    public function longitudeRotation(
1580
        Geographic $to,
1581
        Angle $longitudeOffset
1582
    ): self {
1583 9
        $newLongitude = $this->longitude->add($longitudeOffset);
1584
1585 9
        return static::create($this->latitude, $newLongitude, $this->height, $to, $this->epoch);
1586
    }
1587
1588
    /**
1589
     * Hotine Oblique Mercator (variant A).
1590
     */
1591 9
    public function obliqueMercatorHotineVariantA(
1592
        Projected $to,
1593
        Angle $latitudeOfProjectionCentre,
1594
        Angle $longitudeOfProjectionCentre,
1595
        Angle $azimuthOfInitialLine,
1596
        Angle $angleFromRectifiedToSkewGrid,
1597
        Scale $scaleFactorOnInitialLine,
1598
        Length $falseEasting,
1599
        Length $falseNorthing
1600
    ): ProjectedPoint {
1601 9
        $latitude = $this->latitude->asRadians()->getValue();
1602 9
        $longitude = $this->longitude->asRadians()->getValue();
1603 9
        $latC = $latitudeOfProjectionCentre->asRadians()->getValue();
1604 9
        $lonC = $longitudeOfProjectionCentre->asRadians()->getValue();
1605 9
        $alphaC = $azimuthOfInitialLine->asRadians()->getValue();
1606 9
        $kC = $scaleFactorOnInitialLine->asUnity()->getValue();
1607 9
        $gammaC = $angleFromRectifiedToSkewGrid->asRadians()->getValue();
1608 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1609 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1610 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1611
1612 9
        $B = sqrt(1 + ($e2 * cos($latC) ** 4 / (1 - $e2)));
1613 9
        $A = $a * $B * $kC * sqrt(1 - $e2) / (1 - $e2 * sin($latC) ** 2);
1614 9
        $tO = tan(M_PI / 4 - $latC / 2) / ((1 - $e * sin($latC)) / (1 + $e * sin($latC))) ** ($e / 2);
1615 9
        $D = $B * sqrt((1 - $e2)) / (cos($latC) * sqrt(1 - $e2 * sin($latC) ** 2));
1616 9
        $DD = max(1, $D ** 2);
1617 9
        $F = $D + sqrt($DD - 1) * static::sign($latC);
1618 9
        $H = $F * ($tO) ** $B;
1619 9
        $G = ($F - 1 / $F) / 2;
1620 9
        $gammaO = self::asin(sin($alphaC) / $D);
1621 9
        $lonO = $lonC - (self::asin($G * tan($gammaO))) / $B;
1622
1623 9
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1624 9
        $Q = $H / $t ** $B;
1625 9
        $S = ($Q - 1 / $Q) / 2;
1626 9
        $T = ($Q + 1 / $Q) / 2;
1627 9
        $V = sin($B * ($longitude - $lonO));
1628 9
        $U = (-$V * cos($gammaO) + $S * sin($gammaO)) / $T;
1629 9
        $v = $A * log((1 - $U) / (1 + $U)) / (2 * $B);
1630 9
        $u = $A * atan2(($S * cos($gammaO) + $V * sin($gammaO)), cos($B * ($longitude - $lonO))) / $B;
1631
1632 9
        $easting = $v * cos($gammaC) + $u * sin($gammaC) + $falseEasting->asMetres()->getValue();
1633 9
        $northing = $u * cos($gammaC) - $v * sin($gammaC) + $falseNorthing->asMetres()->getValue();
1634
1635 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1636
    }
1637
1638
    /**
1639
     * Hotine Oblique Mercator (variant B).
1640
     */
1641 9
    public function obliqueMercatorHotineVariantB(
1642
        Projected $to,
1643
        Angle $latitudeOfProjectionCentre,
1644
        Angle $longitudeOfProjectionCentre,
1645
        Angle $azimuthOfInitialLine,
1646
        Angle $angleFromRectifiedToSkewGrid,
1647
        Scale $scaleFactorOnInitialLine,
1648
        Length $eastingAtProjectionCentre,
1649
        Length $northingAtProjectionCentre
1650
    ): ProjectedPoint {
1651 9
        $latitude = $this->latitude->asRadians()->getValue();
1652 9
        $longitude = $this->longitude->asRadians()->getValue();
1653 9
        $latC = $latitudeOfProjectionCentre->asRadians()->getValue();
1654 9
        $lonC = $longitudeOfProjectionCentre->asRadians()->getValue();
1655 9
        $alphaC = $azimuthOfInitialLine->asRadians()->getValue();
1656 9
        $kC = $scaleFactorOnInitialLine->asUnity()->getValue();
1657 9
        $gammaC = $angleFromRectifiedToSkewGrid->asRadians()->getValue();
1658 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1659 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1660 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1661
1662 9
        $B = sqrt(1 + ($e2 * cos($latC) ** 4 / (1 - $e2)));
1663 9
        $A = $a * $B * $kC * sqrt(1 - $e2) / (1 - $e2 * sin($latC) ** 2);
1664 9
        $tO = tan(M_PI / 4 - $latC / 2) / ((1 - $e * sin($latC)) / (1 + $e * sin($latC))) ** ($e / 2);
1665 9
        $D = $B * sqrt((1 - $e2)) / (cos($latC) * sqrt(1 - $e2 * sin($latC) ** 2));
1666 9
        $DD = max(1, $D ** 2);
1667 9
        $F = $D + sqrt($DD - 1) * static::sign($latC);
1668 9
        $H = $F * ($tO) ** $B;
1669 9
        $G = ($F - 1 / $F) / 2;
1670 9
        $gammaO = self::asin(sin($alphaC) / $D);
1671 9
        $lonO = $lonC - (self::asin($G * tan($gammaO))) / $B;
1672 9
        $vC = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $vC is dead and can be removed.
Loading history...
1673 9
        if ($alphaC === M_PI / 2) {
1674
            $uC = $A * ($lonC - $lonO);
1675
        } else {
1676 9
            $uC = ($A / $B) * atan2(sqrt($DD - 1), cos($alphaC)) * static::sign($latC);
1677
        }
1678
1679 9
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1680 9
        $Q = $H / $t ** $B;
1681 9
        $S = ($Q - 1 / $Q) / 2;
1682 9
        $T = ($Q + 1 / $Q) / 2;
1683 9
        $V = sin($B * ($longitude - $lonO));
1684 9
        $U = (-$V * cos($gammaO) + $S * sin($gammaO)) / $T;
1685 9
        $v = $A * log((1 - $U) / (1 + $U)) / (2 * $B);
1686
1687 9
        if ($alphaC === M_PI / 2) {
1688
            if ($longitude === $lonC) {
1689
                $u = 0;
1690
            } else {
1691
                $u = ($A * atan(($S * cos($gammaO) + $V * sin($gammaO)) / cos($B * ($longitude - $lonO))) / $B) - (abs($uC) * static::sign($latC) * static::sign($lonC - $longitude));
1692
            }
1693
        } else {
1694 9
            $u = ($A * atan2(($S * cos($gammaO) + $V * sin($gammaO)), cos($B * ($longitude - $lonO))) / $B) - (abs($uC) * static::sign($latC));
1695
        }
1696
1697 9
        $easting = $v * cos($gammaC) + $u * sin($gammaC) + $eastingAtProjectionCentre->asMetres()->getValue();
1698 9
        $northing = $u * cos($gammaC) - $v * sin($gammaC) + $northingAtProjectionCentre->asMetres()->getValue();
1699
1700 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1701
    }
1702
1703
    /**
1704
     * Laborde Oblique Mercator.
1705
     */
1706 9
    public function obliqueMercatorLaborde(
1707
        Projected $to,
1708
        Angle $latitudeOfProjectionCentre,
1709
        Angle $longitudeOfProjectionCentre,
1710
        Angle $azimuthOfInitialLine,
1711
        Scale $scaleFactorOnInitialLine,
1712
        Length $falseEasting,
1713
        Length $falseNorthing
1714
    ): ProjectedPoint {
1715 9
        $latitude = $this->latitude->asRadians()->getValue();
1716 9
        $latC = $latitudeOfProjectionCentre->asRadians()->getValue();
1717 9
        $alphaC = $azimuthOfInitialLine->asRadians()->getValue();
1718 9
        $kC = $scaleFactorOnInitialLine->asUnity()->getValue();
1719 9
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1720 9
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1721 9
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1722
1723 9
        $B = sqrt(1 + ($e2 * cos($latC) ** 4 / (1 - $e2)));
1724 9
        $latS = self::asin(sin($latC) / $B);
1725 9
        $R = $a * $kC * (sqrt(1 - $e2) / (1 - $e2 * sin($latC) ** 2));
1726 9
        $C = log(tan(M_PI / 4 + $latS / 2)) - $B * log(tan(M_PI / 4 + $latC / 2) * ((1 - $e * sin($latC)) / (1 + $e * sin($latC))) ** ($e / 2));
1727
1728 9
        $L = $B * $this->normaliseLongitude($this->longitude->subtract($longitudeOfProjectionCentre))->asRadians()->getValue();
1729 9
        $q = $C + $B * log(tan(M_PI / 4 + $latitude / 2) * ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2));
1730 9
        $P = 2 * atan(M_E ** $q) - M_PI / 2;
1731 9
        $U = cos($P) * cos($L) * cos($latS) + sin($P) * sin($latS);
1732 9
        $V = cos($P) * cos($L) * sin($latS) - sin($P) * cos($latS);
1733 9
        $W = cos($P) * sin($L);
1734 9
        $d = hypot($U, $V);
1735 9
        if ($d === 0.0) {
1736
            $LPrime = 0;
1737
            $PPrime = static::sign($W) * M_PI / 2;
1738
        } else {
1739 9
            $LPrime = 2 * atan($V / ($U + $d));
1740 9
            $PPrime = atan($W / $d);
1741
        }
1742 9
        $H = new ComplexNumber(-$LPrime, log(tan(M_PI / 4 + $PPrime / 2)));
1743 9
        $G = (new ComplexNumber(1 - cos(2 * $alphaC), sin(2 * $alphaC)))->divide(new ComplexNumber(12, 0));
1744
1745 9
        $easting = $falseEasting->asMetres()->getValue() + $R * $H->pow(3)->multiply($G)->add($H)->getImaginary();
1746 9
        $northing = $falseNorthing->asMetres()->getValue() + $R * $H->pow(3)->multiply($G)->add($H)->getReal();
1747
1748 9
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1749
    }
1750
1751
    /**
1752
     * Transverse Mercator.
1753
     */
1754 112
    public function transverseMercator(
1755
        Projected $to,
1756
        Angle $latitudeOfNaturalOrigin,
1757
        Angle $longitudeOfNaturalOrigin,
1758
        Scale $scaleFactorAtNaturalOrigin,
1759
        Length $falseEasting,
1760
        Length $falseNorthing
1761
    ): ProjectedPoint {
1762 112
        $latitude = $this->latitude->asRadians()->getValue();
1763 112
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
1764 112
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
1765 112
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1766 112
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1767 112
        $f = $this->crs->getDatum()->getEllipsoid()->getInverseFlattening();
1768
1769 112
        $n = $f / (2 - $f);
1770 112
        $B = ($a / (1 + $n)) * (1 + $n ** 2 / 4 + $n ** 4 / 64);
1771
1772 112
        $h1 = $n / 2 - (2 / 3) * $n ** 2 + (5 / 16) * $n ** 3 + (41 / 180) * $n ** 4;
1773 112
        $h2 = (13 / 48) * $n ** 2 - (3 / 5) * $n ** 3 + (557 / 1440) * $n ** 4;
1774 112
        $h3 = (61 / 240) * $n ** 3 - (103 / 140) * $n ** 4;
1775 112
        $h4 = (49561 / 161280) * $n ** 4;
1776
1777 112
        if ($latitudeOrigin === 0.0) {
0 ignored issues
show
introduced by
The condition $latitudeOrigin === 0.0 is always false.
Loading history...
1778 81
            $mO = 0;
1779 31
        } elseif ($latitudeOrigin === M_PI / 2) {
1780
            $mO = $B * M_PI / 2;
1781 31
        } elseif ($latitudeOrigin === -M_PI / 2) {
1782
            $mO = $B * -M_PI / 2;
1783
        } else {
1784 31
            $qO = asinh(tan($latitudeOrigin)) - ($e * atanh($e * sin($latitudeOrigin)));
1785 31
            $betaO = atan(sinh($qO));
1786 31
            $xiO0 = self::asin(sin($betaO));
1787 31
            $xiO1 = $h1 * sin(2 * $xiO0);
1788 31
            $xiO2 = $h2 * sin(4 * $xiO0);
1789 31
            $xiO3 = $h3 * sin(6 * $xiO0);
1790 31
            $xiO4 = $h4 * sin(8 * $xiO0);
1791 31
            $xiO = $xiO0 + $xiO1 + $xiO2 + $xiO3 + $xiO4;
1792 31
            $mO = $B * $xiO;
1793
        }
1794
1795 112
        $Q = asinh(tan($latitude)) - ($e * atanh($e * sin($latitude)));
1796 112
        $beta = atan(sinh($Q));
1797 112
        $eta0 = atanh(cos($beta) * sin($this->normaliseLongitude($this->longitude->subtract($longitudeOfNaturalOrigin))->asRadians()->getValue()));
1798 112
        $xi0 = self::asin(sin($beta) * cosh($eta0));
1799 112
        $xi1 = $h1 * sin(2 * $xi0) * cosh(2 * $eta0);
1800 112
        $eta1 = $h1 * cos(2 * $xi0) * sinh(2 * $eta0);
1801 112
        $xi2 = $h2 * sin(4 * $xi0) * cosh(4 * $eta0);
1802 112
        $eta2 = $h2 * cos(4 * $xi0) * sinh(4 * $eta0);
1803 112
        $xi3 = $h3 * sin(6 * $xi0) * cosh(6 * $eta0);
1804 112
        $eta3 = $h3 * cos(6 * $xi0) * sinh(6 * $eta0);
1805 112
        $xi4 = $h4 * sin(8 * $xi0) * cosh(8 * $eta0);
1806 112
        $eta4 = $h4 * cos(8 * $xi0) * sinh(8 * $eta0);
1807 112
        $xi = $xi0 + $xi1 + $xi2 + $xi3 + $xi4;
1808 112
        $eta = $eta0 + $eta1 + $eta2 + $eta3 + $eta4;
1809
1810 112
        $easting = $falseEasting->asMetres()->getValue() + $kO * $B * $eta;
1811 112
        $northing = $falseNorthing->asMetres()->getValue() + $kO * ($B * $xi - $mO);
1812
1813 112
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1814
    }
1815
1816
    /**
1817
     * Transverse Mercator Zoned Grid System
1818
     * If locations fall outwith the fixed zones the general Transverse Mercator method (code 9807) must be used for
1819
     * each zone.
1820
     */
1821 36
    public function transverseMercatorZonedGrid(
1822
        Projected $to,
1823
        Angle $latitudeOfNaturalOrigin,
1824
        Angle $initialLongitude,
1825
        Angle $zoneWidth,
1826
        Scale $scaleFactorAtNaturalOrigin,
1827
        Length $falseEasting,
1828
        Length $falseNorthing
1829
    ): ProjectedPoint {
1830 36
        $W = $zoneWidth->asDegrees()->getValue();
1831 36
        $Z = (int) ($this->longitude->subtract($initialLongitude)->asDegrees()->getValue() / $W) % (int) (360 / $W) + 1;
1832
1833 36
        $longitudeOrigin = $initialLongitude->add(new Degree($Z * $W - $W / 2));
1834 36
        $falseEasting = $falseEasting->add(new Metre($Z * 1000000));
1835
1836 36
        return $this->transverseMercator($to, $latitudeOfNaturalOrigin, $longitudeOrigin, $scaleFactorAtNaturalOrigin, $falseEasting, $falseNorthing);
1837
    }
1838
1839
    /**
1840
     * New Zealand Map Grid.
1841
     */
1842 27
    public function newZealandMapGrid(
1843
        Projected $to,
1844
        Angle $latitudeOfNaturalOrigin,
1845
        Angle $longitudeOfNaturalOrigin,
1846
        Length $falseEasting,
1847
        Length $falseNorthing
1848
    ): ProjectedPoint {
1849 27
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1850
1851 27
        $deltaLatitudeToOrigin = Angle::convert($this->latitude->subtract($latitudeOfNaturalOrigin), Angle::EPSG_ARC_SECOND)->getValue();
1852 27
        $deltaLongitudeToOrigin = $this->longitude->subtract($longitudeOfNaturalOrigin)->asRadians();
1853
1854 27
        $deltaPsi = 0;
1855 27
        $deltaPsi += 0.6399175073 * ($deltaLatitudeToOrigin * 0.00001) ** 1;
1856 27
        $deltaPsi += -0.1358797613 * ($deltaLatitudeToOrigin * 0.00001) ** 2;
1857 27
        $deltaPsi += 0.063294409 * ($deltaLatitudeToOrigin * 0.00001) ** 3;
1858 27
        $deltaPsi += -0.02526853 * ($deltaLatitudeToOrigin * 0.00001) ** 4;
1859 27
        $deltaPsi += 0.0117879 * ($deltaLatitudeToOrigin * 0.00001) ** 5;
1860 27
        $deltaPsi += -0.0055161 * ($deltaLatitudeToOrigin * 0.00001) ** 6;
1861 27
        $deltaPsi += 0.0026906 * ($deltaLatitudeToOrigin * 0.00001) ** 7;
1862 27
        $deltaPsi += -0.001333 * ($deltaLatitudeToOrigin * 0.00001) ** 8;
1863 27
        $deltaPsi += 0.00067 * ($deltaLatitudeToOrigin * 0.00001) ** 9;
1864 27
        $deltaPsi += -0.00034 * ($deltaLatitudeToOrigin * 0.00001) ** 10;
1865
1866 27
        $zeta = new ComplexNumber($deltaPsi, $deltaLongitudeToOrigin->getValue());
1867
1868 27
        $B1 = new ComplexNumber(0.7557853228, 0.0);
1869 27
        $B2 = new ComplexNumber(0.249204646, 0.003371507);
1870 27
        $B3 = new ComplexNumber(-0.001541739, 0.041058560);
1871 27
        $B4 = new ComplexNumber(-0.10162907, 0.01727609);
1872 27
        $B5 = new ComplexNumber(-0.26623489, -0.36249218);
1873 27
        $B6 = new ComplexNumber(-0.6870983, -1.1651967);
1874 27
        $z = new ComplexNumber(0, 0);
1875 27
        $z = $z->add($B1->multiply($zeta->pow(1)));
1876 27
        $z = $z->add($B2->multiply($zeta->pow(2)));
1877 27
        $z = $z->add($B3->multiply($zeta->pow(3)));
1878 27
        $z = $z->add($B4->multiply($zeta->pow(4)));
1879 27
        $z = $z->add($B5->multiply($zeta->pow(5)));
1880 27
        $z = $z->add($B6->multiply($zeta->pow(6)));
1881
1882 27
        $easting = $falseEasting->asMetres()->getValue() + $z->getImaginary() * $a;
1883 27
        $northing = $falseNorthing->asMetres()->getValue() + $z->getReal() * $a;
1884
1885 27
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1886
    }
1887
1888
    /**
1889
     * Madrid to ED50 polynomial.
1890
     */
1891 9
    public function madridToED50Polynomial(
1892
        Geographic2D $to,
1893
        Scale $A0,
1894
        Scale $A1,
1895
        Scale $A2,
1896
        Scale $A3,
1897
        Angle $B00,
1898
        Scale $B0,
1899
        Scale $B1,
1900
        Scale $B2,
1901
        Scale $B3
1902
    ): self {
1903 9
        $dLatitude = new ArcSecond($A0->add($A1->multiply($this->latitude->getValue()))->add($A2->multiply($this->longitude->getValue()))->add($A3->multiply($this->height ? $this->height->getValue() : 0))->getValue());
1904 9
        $dLongitude = $B00->add(new ArcSecond($B0->add($B1->multiply($this->latitude->getValue()))->add($B2->multiply($this->longitude->getValue()))->add($B3->multiply($this->height ? $this->height->getValue() : 0))->getValue()));
1905
1906 9
        return self::create($this->latitude->add($dLatitude), $this->longitude->add($dLongitude), null, $to, $this->epoch);
1907
    }
1908
1909
    /**
1910
     * Geographic3D to 2D conversion.
1911
     */
1912 27
    public function threeDToTwoD(
1913
        Geographic $to
1914
    ): self {
1915 27
        if ($to instanceof Geographic2D) {
1916 27
            return static::create($this->latitude, $this->longitude, null, $to, $this->epoch);
1917
        }
1918
1919
        return static::create($this->latitude, $this->longitude, new Metre(0), $to, $this->epoch);
1920
    }
1921
1922
    /**
1923
     * Geographic2D offsets.
1924
     * This transformation allows calculation of coordinates in the target system by adding the parameter value to the
1925
     * coordinate values of the point in the source system.
1926
     */
1927 9
    public function geographic2DOffsets(
1928
        Geographic $to,
1929
        Angle $latitudeOffset,
1930
        Angle $longitudeOffset
1931
    ): self {
1932 9
        $toLatitude = $this->latitude->add($latitudeOffset);
1933 9
        $toLongitude = $this->longitude->add($longitudeOffset);
1934
1935 9
        return static::create($toLatitude, $toLongitude, null, $to, $this->epoch);
1936
    }
1937
1938
    /*
1939
     * Geographic2D with Height Offsets.
1940
     * This transformation allows calculation of coordinates in the target system by adding the parameter value to the
1941
     * coordinate values of the point in the source system.
1942
     */
1943
    public function geographic2DWithHeightOffsets(
1944
        Compound $to,
1945
        Angle $latitudeOffset,
1946
        Angle $longitudeOffset,
1947
        Length $geoidUndulation
1948
    ): CompoundPoint {
1949
        $toLatitude = $this->latitude->add($latitudeOffset);
1950
        $toLongitude = $this->longitude->add($longitudeOffset);
1951
        $toHeight = $this->height->add($geoidUndulation);
0 ignored issues
show
Bug introduced by
The method add() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1951
        /** @scrutinizer ignore-call */ 
1952
        $toHeight = $this->height->add($geoidUndulation);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1952
1953
        $horizontal = static::create($toLatitude, $toLongitude, null, $to->getHorizontal(), $this->epoch);
1954
        $vertical = VerticalPoint::create($toHeight, $to->getVertical(), $this->epoch);
0 ignored issues
show
Bug introduced by
It seems like $toHeight can also be of type null; however, parameter $height of PHPCoord\VerticalPoint::create() does only seem to accept PHPCoord\UnitOfMeasure\Length\Length, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1954
        $vertical = VerticalPoint::create(/** @scrutinizer ignore-type */ $toHeight, $to->getVertical(), $this->epoch);
Loading history...
1955
1956
        return CompoundPoint::create($horizontal, $vertical, $to, $this->epoch);
1957
    }
1958
1959
    /**
1960
     * General polynomial.
1961
     * @param Coefficient[] $powerCoefficients
1962
     */
1963 18
    public function generalPolynomial(
1964
        Geographic $to,
1965
        Angle $ordinate1OfEvaluationPointInSourceCRS,
1966
        Angle $ordinate2OfEvaluationPointInSourceCRS,
1967
        Angle $ordinate1OfEvaluationPointInTargetCRS,
1968
        Angle $ordinate2OfEvaluationPointInTargetCRS,
1969
        Scale $scalingFactorForSourceCRSCoordDifferences,
1970
        Scale $scalingFactorForTargetCRSCoordDifferences,
1971
        Scale $A0,
1972
        Scale $B0,
1973
        array $powerCoefficients
1974
    ): self {
1975 18
        $xs = $this->latitude->getValue();
1976 18
        $ys = $this->longitude->getValue();
1977
1978 18
        $t = $this->generalPolynomialUnitless(
1979 18
            $xs,
1980
            $ys,
1981
            $ordinate1OfEvaluationPointInSourceCRS,
1982
            $ordinate2OfEvaluationPointInSourceCRS,
1983
            $ordinate1OfEvaluationPointInTargetCRS,
1984
            $ordinate2OfEvaluationPointInTargetCRS,
1985
            $scalingFactorForSourceCRSCoordDifferences,
1986
            $scalingFactorForTargetCRSCoordDifferences,
1987
            $A0,
1988
            $B0,
1989
            $powerCoefficients
1990
        );
1991
1992 18
        $xtUnit = $to->getCoordinateSystem()->getAxes()[0]->getUnitOfMeasureId();
1993 18
        if ($xtUnit === Angle::EPSG_DEGREE_SUPPLIER_TO_DEFINE_REPRESENTATION) {
1994 18
            $xtUnit = Angle::EPSG_DEGREE;
1995
        }
1996 18
        $ytUnit = $to->getCoordinateSystem()->getAxes()[1]->getUnitOfMeasureId();
1997 18
        if ($ytUnit === Angle::EPSG_DEGREE_SUPPLIER_TO_DEFINE_REPRESENTATION) {
1998 18
            $ytUnit = Angle::EPSG_DEGREE;
1999
        }
2000
2001 18
        return static::create(
2002 18
            Angle::makeUnit($t['xt'], $xtUnit),
2003 18
            Angle::makeUnit($t['yt'], $ytUnit),
2004 18
            $this->height,
2005
            $to,
2006 18
            $this->epoch
2007
        );
2008
    }
2009
2010
    /**
2011
     * Reversible polynomial.
2012
     * @param Coefficient[] $powerCoefficients
2013
     */
2014 36
    public function reversiblePolynomial(
2015
        Geographic $to,
2016
        Angle $ordinate1OfEvaluationPoint,
2017
        Angle $ordinate2OfEvaluationPoint,
2018
        Scale $scalingFactorForCoordDifferences,
2019
        Scale $A0,
2020
        Scale $B0,
2021
        $powerCoefficients
2022
    ): self {
2023 36
        $xs = $this->latitude->getValue();
2024 36
        $ys = $this->longitude->getValue();
2025
2026 36
        $t = $this->reversiblePolynomialUnitless(
2027 36
            $xs,
2028
            $ys,
2029
            $ordinate1OfEvaluationPoint,
2030
            $ordinate2OfEvaluationPoint,
2031
            $scalingFactorForCoordDifferences,
2032
            $A0,
2033
            $B0,
2034
            $powerCoefficients
2035
        );
2036
2037 36
        $xtUnit = $to->getCoordinateSystem()->getAxes()[0]->getUnitOfMeasureId();
2038 36
        if ($xtUnit === Angle::EPSG_DEGREE_SUPPLIER_TO_DEFINE_REPRESENTATION) {
2039 36
            $xtUnit = Angle::EPSG_DEGREE;
2040
        }
2041 36
        $ytUnit = $to->getCoordinateSystem()->getAxes()[1]->getUnitOfMeasureId();
2042 36
        if ($ytUnit === Angle::EPSG_DEGREE_SUPPLIER_TO_DEFINE_REPRESENTATION) {
2043 36
            $ytUnit = Angle::EPSG_DEGREE;
2044
        }
2045
2046 36
        return static::create(
2047 36
            Angle::makeUnit($t['xt'], $xtUnit),
2048 36
            Angle::makeUnit($t['yt'], $ytUnit),
2049 36
            $this->height,
2050
            $to,
2051 36
            $this->epoch
2052
        );
2053
    }
2054
2055
    /**
2056
     * Axis Order Reversal.
2057
     */
2058
    public function axisReversal(
2059
        Geographic $to
2060
    ): self {
2061
        // axes are read in from the CRS, this is a book-keeping adjustment only
2062
        return static::create($this->latitude, $this->longitude, $this->height, $to, $this->epoch);
2063
    }
2064
2065
    /**
2066
     * Ordnance Survey National Transformation
2067
     * Geodetic transformation between ETRS89 (or WGS 84) and OSGB36 / National Grid.  Uses ETRS89 / National Grid as
2068
     * an intermediate coordinate system for bi-linear interpolation of gridded grid coordinate differences.
2069
     */
2070 2
    public function OSTN15(
2071
        Projected $to,
0 ignored issues
show
Unused Code introduced by
The parameter $to is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

2071
        /** @scrutinizer ignore-unused */ Projected $to,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2072
        OSTNOSGM15Grid $eastingAndNorthingDifferenceFile
2073
    ): ProjectedPoint {
2074 2
        $osgb36NationalGrid = Projected::fromSRID(Projected::EPSG_OSGB36_BRITISH_NATIONAL_GRID);
2075 2
        $etrs89NationalGrid = new Projected(
2076 2
            'ETRS89 / National Grid',
2077 2
            Cartesian::fromSRID(Cartesian::EPSG_2D_AXES_EASTING_NORTHING_E_N_ORIENTATIONS_EAST_NORTH_UOM_M),
2078 2
            Datum::fromSRID(Datum::EPSG_EUROPEAN_TERRESTRIAL_REFERENCE_SYSTEM_1989_ENSEMBLE),
2079 2
            $osgb36NationalGrid->getBoundingArea()
2080
        );
2081
2082 2
        $projected = $this->transverseMercator($etrs89NationalGrid, new Degree(49), new Degree(-2), new Unity(0.9996012717), new Metre(400000), new Metre(-100000));
2083
2084 2
        return $eastingAndNorthingDifferenceFile->applyForwardHorizontalAdjustment($projected);
2085
    }
2086
2087
    /**
2088
     * Geog3D to Geog2D+GravityRelatedHeight (OSGM-GB).
2089
     * Uses ETRS89 / National Grid as an intermediate coordinate system for bi-linear interpolation of gridded grid
2090
     * coordinate differences.
2091
     */
2092 1
    public function geographic3DTo2DPlusGravityHeightOSGM15(
2093
        Compound $to,
2094
        OSTNOSGM15Grid $geoidHeightCorrectionModelFile
2095
    ): CompoundPoint {
2096 1
        $osgb36NationalGrid = Projected::fromSRID(Projected::EPSG_OSGB36_BRITISH_NATIONAL_GRID);
2097 1
        $etrs89NationalGrid = new Projected(
2098 1
            'ETRS89 / National Grid',
2099 1
            Cartesian::fromSRID(Cartesian::EPSG_2D_AXES_EASTING_NORTHING_E_N_ORIENTATIONS_EAST_NORTH_UOM_M),
2100 1
            Datum::fromSRID(Datum::EPSG_EUROPEAN_TERRESTRIAL_REFERENCE_SYSTEM_1989_ENSEMBLE),
2101 1
            $osgb36NationalGrid->getBoundingArea()
2102
        );
2103
2104 1
        $projected = $this->transverseMercator($etrs89NationalGrid, new Degree(49), new Degree(-2), new Unity(0.9996012717), new Metre(400000), new Metre(-100000));
2105
2106 1
        $horizontalPoint = self::create(
2107 1
            $this->latitude,
2108 1
            $this->longitude,
2109 1
            null,
2110 1
            $to->getHorizontal(),
2111 1
            $this->getCoordinateEpoch()
2112
        );
2113
2114 1
        $verticalPoint = VerticalPoint::create(
2115 1
            $this->height->subtract($geoidHeightCorrectionModelFile->getVerticalAdjustment($projected)),
0 ignored issues
show
Bug introduced by
It seems like $this->height->subtract(...Adjustment($projected)) can also be of type null; however, parameter $height of PHPCoord\VerticalPoint::create() does only seem to accept PHPCoord\UnitOfMeasure\Length\Length, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

2115
            /** @scrutinizer ignore-type */ $this->height->subtract($geoidHeightCorrectionModelFile->getVerticalAdjustment($projected)),
Loading history...
2116 1
            $to->getVertical(),
2117 1
            $this->getCoordinateEpoch()
2118
        );
2119
2120 1
        return CompoundPoint::create(
2121 1
            $horizontalPoint,
2122 1
            $verticalPoint,
2123 1
            $to,
2124 1
            $this->getCoordinateEpoch()
2125
        );
2126
    }
2127
2128
    /**
2129
     * Geographic3D to GravityRelatedHeight (OSGM-GB).
2130
     * Uses ETRS89 / National Grid as an intermediate coordinate system for bi-linear interpolation of gridded grid
2131
     * coordinate differences.
2132
     */
2133 1
    public function geographic3DToGravityHeightOSGM15(
2134
        Vertical $to,
2135
        OSTNOSGM15Grid $geoidHeightCorrectionModelFile
2136
    ): VerticalPoint {
2137 1
        $osgb36NationalGrid = Projected::fromSRID(Projected::EPSG_OSGB36_BRITISH_NATIONAL_GRID);
2138 1
        $etrs89NationalGrid = new Projected(
2139 1
            'ETRS89 / National Grid',
2140 1
            Cartesian::fromSRID(Cartesian::EPSG_2D_AXES_EASTING_NORTHING_E_N_ORIENTATIONS_EAST_NORTH_UOM_M),
2141 1
            Datum::fromSRID(Datum::EPSG_EUROPEAN_TERRESTRIAL_REFERENCE_SYSTEM_1989_ENSEMBLE),
2142 1
            $osgb36NationalGrid->getBoundingArea()
2143
        );
2144
2145 1
        $projected = $this->transverseMercator($etrs89NationalGrid, new Degree(49), new Degree(-2), new Unity(0.9996012717), new Metre(400000), new Metre(-100000));
2146
2147 1
        return VerticalPoint::create(
2148 1
            $this->height->subtract($geoidHeightCorrectionModelFile->getVerticalAdjustment($projected)),
0 ignored issues
show
Bug introduced by
It seems like $this->height->subtract(...Adjustment($projected)) can also be of type null; however, parameter $height of PHPCoord\VerticalPoint::create() does only seem to accept PHPCoord\UnitOfMeasure\Length\Length, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

2148
            /** @scrutinizer ignore-type */ $this->height->subtract($geoidHeightCorrectionModelFile->getVerticalAdjustment($projected)),
Loading history...
2149 1
            $to,
2150 1
            $this->getCoordinateEpoch()
2151
        );
2152
    }
2153
2154
    /**
2155
     * Geog3D to Geog2D+GravityRelatedHeight (gtx).
2156
     */
2157 1
    public function geographic3DTo2DPlusGravityHeightGTX(
2158
        Compound $to,
2159
        GTXGrid $geoidHeightCorrectionModelFile
2160
    ): CompoundPoint {
2161 1
        $horizontalPoint = self::create(
2162 1
            $this->latitude,
2163 1
            $this->longitude,
2164 1
            null,
2165 1
            $to->getHorizontal(),
2166 1
            $this->getCoordinateEpoch()
2167
        );
2168
2169 1
        $verticalPoint = VerticalPoint::create(
2170 1
            $this->height->subtract($geoidHeightCorrectionModelFile->getAdjustment($this)),
0 ignored issues
show
Bug introduced by
It seems like $this->height->subtract(...->getAdjustment($this)) can also be of type null; however, parameter $height of PHPCoord\VerticalPoint::create() does only seem to accept PHPCoord\UnitOfMeasure\Length\Length, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

2170
            /** @scrutinizer ignore-type */ $this->height->subtract($geoidHeightCorrectionModelFile->getAdjustment($this)),
Loading history...
2171 1
            $to->getVertical(),
2172 1
            $this->getCoordinateEpoch()
2173
        );
2174
2175 1
        return CompoundPoint::create(
2176 1
            $horizontalPoint,
2177 1
            $verticalPoint,
2178 1
            $to,
2179 1
            $this->getCoordinateEpoch()
2180
        );
2181
    }
2182
2183
    /**
2184
     * Geographic3D to GravityRelatedHeight (gtx).
2185
     */
2186 1
    public function geographic3DToGravityHeightGTX(
2187
        Vertical $to,
2188
        GTXGrid $geoidHeightCorrectionModelFile
2189
    ): VerticalPoint {
2190 1
        return VerticalPoint::create(
2191 1
            $this->height->subtract($geoidHeightCorrectionModelFile->getAdjustment($this)),
0 ignored issues
show
Bug introduced by
It seems like $this->height->subtract(...->getAdjustment($this)) can also be of type null; however, parameter $height of PHPCoord\VerticalPoint::create() does only seem to accept PHPCoord\UnitOfMeasure\Length\Length, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

2191
            /** @scrutinizer ignore-type */ $this->height->subtract($geoidHeightCorrectionModelFile->getAdjustment($this)),
Loading history...
2192 1
            $to,
2193 1
            $this->getCoordinateEpoch()
2194
        );
2195
    }
2196
2197
    /**
2198
     * NADCON5.
2199
     * Geodetic transformation operating on geographic coordinate differences by bi-quadratic interpolation.  Input
2200
     * expects longitudes to be positive east in range 0-360° (0° = Greenwich).
2201
     */
2202 7
    public function NADCON5(
2203
        Geographic $to,
2204
        NADCON5Grid $latitudeDifferenceFile,
2205
        NADCON5Grid $longitudeDifferenceFile,
2206
        ?NADCON5Grid $ellipsoidalHeightDifferenceFile,
2207
        bool $inReverse
2208
    ): self {
2209
        /*
2210
         * Ideally most of this logic (especially reverse case) would be in the NADCON5Grid class like the other grids,
2211
         * but NADCON5 uses different files for latitude/longitude/height that need to be combined at runtime so that
2212
         * isn't possible.
2213
         */
2214 7
        if (!$inReverse) {
2215 4
            $latitudeAdjustment = new ArcSecond($latitudeDifferenceFile->getForwardAdjustment($this));
2216 4
            $longitudeAdjustment = new ArcSecond($longitudeDifferenceFile->getForwardAdjustment($this));
2217 4
            $heightAdjustment = $this->getHeight() && $ellipsoidalHeightDifferenceFile ? new Metre($ellipsoidalHeightDifferenceFile->getForwardAdjustment($this)) : null;
2218
2219 4
            return self::create($this->latitude->add($latitudeAdjustment), $this->longitude->add($longitudeAdjustment), $heightAdjustment ? $this->height->add($heightAdjustment) : null, $to, $this->getCoordinateEpoch());
2220
        }
2221
2222 3
        $iteration = $this;
2223
2224
        do {
2225 3
            $prevIteration = $iteration;
2226 3
            $latitudeAdjustment = new ArcSecond($latitudeDifferenceFile->getForwardAdjustment($iteration));
2227 3
            $longitudeAdjustment = new ArcSecond($longitudeDifferenceFile->getForwardAdjustment($iteration));
2228 3
            $heightAdjustment = $this->getHeight() && $ellipsoidalHeightDifferenceFile ? new Metre($ellipsoidalHeightDifferenceFile->getForwardAdjustment($iteration)) : null;
2229 3
            $iteration = self::create($this->latitude->subtract($latitudeAdjustment), $this->longitude->subtract($longitudeAdjustment), $heightAdjustment ? $this->height->subtract($heightAdjustment) : null, $to, $this->getCoordinateEpoch());
2230 3
        } while (abs($iteration->latitude->subtract($prevIteration->latitude)->getValue()) > self::ITERATION_CONVERGENCE_GRID && abs($iteration->longitude->subtract($prevIteration->longitude)->getValue()) > self::ITERATION_CONVERGENCE_GRID && ($this->height === null || abs($iteration->height->subtract($prevIteration->height)->getValue()) > self::ITERATION_CONVERGENCE_GRID));
0 ignored issues
show
Bug introduced by
It seems like $prevIteration->height can also be of type null; however, parameter $unit of PHPCoord\UnitOfMeasure\Length\Length::subtract() does only seem to accept PHPCoord\UnitOfMeasure\Length\Length, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

2230
        } while (abs($iteration->latitude->subtract($prevIteration->latitude)->getValue()) > self::ITERATION_CONVERGENCE_GRID && abs($iteration->longitude->subtract($prevIteration->longitude)->getValue()) > self::ITERATION_CONVERGENCE_GRID && ($this->height === null || abs($iteration->height->subtract(/** @scrutinizer ignore-type */ $prevIteration->height)->getValue()) > self::ITERATION_CONVERGENCE_GRID));
Loading history...
Bug introduced by
The method subtract() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

2230
        } while (abs($iteration->latitude->subtract($prevIteration->latitude)->getValue()) > self::ITERATION_CONVERGENCE_GRID && abs($iteration->longitude->subtract($prevIteration->longitude)->getValue()) > self::ITERATION_CONVERGENCE_GRID && ($this->height === null || abs($iteration->height->/** @scrutinizer ignore-call */ subtract($prevIteration->height)->getValue()) > self::ITERATION_CONVERGENCE_GRID));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
2231
2232 3
        return $iteration;
2233
    }
2234
2235
    /**
2236
     * NTv2
2237
     * Geodetic transformation operating on geographic coordinate differences by bi-linear interpolation.  Supersedes
2238
     * NTv1 (transformation method code 9614).  Input expects longitudes to be positive west.
2239
     */
2240 5
    public function NTv2(
2241
        Geographic $to,
2242
        NTv2Grid $latitudeAndLongitudeDifferenceFile,
2243
        bool $inReverse
2244
    ): self {
2245 5
        if (!$inReverse) {
2246 3
            return $latitudeAndLongitudeDifferenceFile->applyForwardAdjustment($this, $to);
2247
        }
2248
2249 2
        return $latitudeAndLongitudeDifferenceFile->applyReverseAdjustment($this, $to);
2250
    }
2251
2252
    /**
2253
     * Geocentric translation by Grid Interpolation (IGN France).
2254
     */
2255 3
    public function geocentricTranslationByGridInterpolationIGNF(
2256
        Geographic $to,
2257
        IGNGeocentricTranslationGrid $geocentricTranslationFile,
2258
        bool $inReverse
2259
    ): self {
2260 3
        if (!$inReverse) {
2261 2
            return $geocentricTranslationFile->applyForwardAdjustment($this, $to);
2262
        }
2263
2264 1
        return $geocentricTranslationFile->applyReverseAdjustment($this, $to);
2265
    }
2266
2267 352
    public function asGeographicValue(): GeographicValue
2268
    {
2269 352
        return new GeographicValue($this->latitude, $this->longitude, $this->height, $this->crs->getDatum());
2270
    }
2271
2272 18
    public function asUTMPoint(): UTMPoint
2273
    {
2274 18
        $hemisphere = $this->getLatitude()->asDegrees()->getValue() >= 0 ? UTMPoint::HEMISPHERE_NORTH : UTMPoint::HEMISPHERE_SOUTH;
2275 18
        $latitudeOfNaturalOrigin = new Degree(0);
2276 18
        $initialLongitude = new Degree(-180);
2277 18
        $scaleFactorAtNaturalOrigin = new Unity(0.9996);
2278 18
        $falseEasting = new Metre(500000);
2279 18
        $falseNorthing = $hemisphere === UTMPoint::HEMISPHERE_NORTH ? new Metre(0) : new Metre(10000000);
2280 18
        $Z = (int) ($this->longitude->subtract($initialLongitude)->asDegrees()->getValue() / 6) % (360 / 6) + 1;
2281 18
        $longitudeOrigin = $initialLongitude->add(new Degree($Z * 6 - 3));
2282
2283 18
        $projectedCRS = new Projected(
2284 18
            'UTM/' . $this->crs->getSRID(),
2285 18
            Cartesian::fromSRID(Cartesian::EPSG_2D_AXES_EASTING_NORTHING_E_N_ORIENTATIONS_EAST_NORTH_UOM_M),
2286 18
            $this->crs->getDatum(),
2287 18
            BoundingArea::createWorld() // this is a dummy CRS for the transform only, details don't matter
2288
        );
2289
2290 18
        $asProjected = $this->transverseMercator($projectedCRS, $latitudeOfNaturalOrigin, $longitudeOrigin, $scaleFactorAtNaturalOrigin, $falseEasting, $falseNorthing);
2291
2292 18
        return new UTMPoint($asProjected->getEasting(), $asProjected->getNorthing(), $Z, $hemisphere, $this->crs, $this->epoch);
2293
    }
2294
}
2295