Passed
Push — master ( 300b0d...3598bd )
by Doug
09:39
created

lambertConicConformal1SPVariantB()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 21
nc 1
nop 7
dl 0
loc 33
ccs 0
cts 22
cp 0
crap 2
rs 9.584
c 0
b 0
f 0
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 implode;
23
use InvalidArgumentException;
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\GeocentricValue;
32
use PHPCoord\CoordinateOperation\GeographicValue;
33
use PHPCoord\CoordinateReferenceSystem\Compound;
34
use PHPCoord\CoordinateReferenceSystem\Geocentric;
35
use PHPCoord\CoordinateReferenceSystem\Geographic;
36
use PHPCoord\CoordinateReferenceSystem\Geographic2D;
37
use PHPCoord\CoordinateReferenceSystem\Geographic3D;
38
use PHPCoord\CoordinateReferenceSystem\Projected;
39
use PHPCoord\CoordinateSystem\Axis;
40
use PHPCoord\Datum\Ellipsoid;
41
use PHPCoord\Exception\InvalidCoordinateReferenceSystemException;
42
use PHPCoord\Exception\UnknownAxisException;
43
use PHPCoord\UnitOfMeasure\Angle\Angle;
44
use PHPCoord\UnitOfMeasure\Angle\ArcSecond;
45
use PHPCoord\UnitOfMeasure\Angle\Degree;
46
use PHPCoord\UnitOfMeasure\Angle\Radian;
47
use PHPCoord\UnitOfMeasure\Length\Length;
48
use PHPCoord\UnitOfMeasure\Length\Metre;
49
use PHPCoord\UnitOfMeasure\Scale\Coefficient;
50
use PHPCoord\UnitOfMeasure\Scale\Scale;
51
use PHPCoord\UnitOfMeasure\Scale\Unity;
52
use function sin;
53
use function sinh;
54
use function sprintf;
55
use function sqrt;
56
use function tan;
57
use TypeError;
58
59
/**
60
 * Coordinate representing a point on an ellipsoid.
61
 */
62
class GeographicPoint extends Point
63
{
64
    use AutoConversion;
65
66
    /**
67
     * Latitude.
68
     */
69
    protected Angle $latitude;
70
71
    /**
72
     * Longitude.
73
     */
74
    protected Angle $longitude;
75
76
    /**
77
     * Height above ellipsoid (N.B. *not* height above ground, sea-level or anything else tangible).
78
     */
79
    protected ?Length $height;
80
81
    /**
82
     * Coordinate reference system.
83
     */
84
    protected Geographic $crs;
85
86
    /**
87
     * Coordinate epoch (date for which the specified coordinates represented this point).
88
     */
89
    protected ?DateTimeImmutable $epoch;
90
91 128
    protected function __construct(Angle $latitude, Angle $longitude, ?Length $height, Geographic $crs, ?DateTimeInterface $epoch = null)
92
    {
93 128
        if (!$crs instanceof Geographic2D && !$crs instanceof Geographic3D) {
94
            throw new TypeError(sprintf("A geographic point must be associated with a geographic CRS, but a '%s' CRS was given", get_class($crs)));
95
        }
96
97 128
        if ($crs instanceof Geographic2D && $height !== null) {
98 1
            throw new InvalidCoordinateReferenceSystemException('A 2D geographic point must not include a height');
99
        }
100
101 127
        if ($crs instanceof Geographic3D && $height === null) {
102 1
            throw new InvalidCoordinateReferenceSystemException('A 3D geographic point must include a height, none given');
103
        }
104
105 126
        $this->crs = $crs;
106
107 126
        $this->latitude = Angle::convert($latitude, $this->getAxisByName(Axis::GEODETIC_LATITUDE)->getUnitOfMeasureId());
108 126
        $this->longitude = Angle::convert($longitude, $this->getAxisByName(Axis::GEODETIC_LONGITUDE)->getUnitOfMeasureId());
109
110 126
        if ($height) {
111 16
            $this->height = Length::convert($height, $this->getAxisByName(Axis::ELLIPSOIDAL_HEIGHT)->getUnitOfMeasureId());
112
        } else {
113 114
            $this->height = null;
114
        }
115
116 126
        if ($epoch instanceof DateTime) {
117 1
            $epoch = DateTimeImmutable::createFromMutable($epoch);
118
        }
119 126
        $this->epoch = $epoch;
120 126
    }
121
122
    /**
123
     * @param Angle   $latitude  refer to CRS for preferred unit of measure, but any angle unit accepted
124
     * @param Angle   $longitude refer to CRS for preferred unit of measure, but any angle unit accepted
125
     * @param ?Length $height    refer to CRS for preferred unit of measure, but any length unit accepted
126
     */
127 128
    public static function create(Angle $latitude, Angle $longitude, ?Length $height, Geographic $crs, ?DateTimeInterface $epoch = null): self
128
    {
129 128
        return new static($latitude, $longitude, $height, $crs, $epoch);
130
    }
131
132 76
    public function getLatitude(): Angle
133
    {
134 76
        return $this->latitude;
135
    }
136
137 76
    public function getLongitude(): Angle
138
    {
139 76
        return $this->longitude;
140
    }
141
142 36
    public function getHeight(): ?Length
143
    {
144 36
        return $this->height;
145
    }
146
147 126
    public function getCRS(): Geographic
148
    {
149 126
        return $this->crs;
150
    }
151
152 12
    public function getCoordinateEpoch(): ?DateTimeImmutable
153
    {
154 12
        return $this->epoch;
155
    }
156
157
    /**
158
     * Calculate surface distance between two points.
159
     */
160 2
    public function calculateDistance(Point $to): Length
161
    {
162 2
        if ($to->getCRS()->getSRID() !== $this->crs->getSRID()) {
163 1
            throw new InvalidArgumentException('Can only calculate distances between two points in the same CRS');
164
        }
165
166
        //Mean radius definition taken from Wikipedia
167
        /** @var Ellipsoid $ellipsoid */
168 1
        $ellipsoid = $this->getCRS()->getDatum()->getEllipsoid();
169 1
        $radius = ((2 * $ellipsoid->getSemiMajorAxis()->asMetres()->getValue()) + $ellipsoid->getSemiMinorAxis()->asMetres()->getValue()) / 3;
170
171 1
        return new Metre(self::acos(sin($this->latitude->asRadians()->getValue()) * sin($to->latitude->asRadians()->getValue()) + cos($this->latitude->asRadians()->getValue()) * cos($to->latitude->asRadians()->getValue()) * cos($to->longitude->asRadians()->getValue() - $this->longitude->asRadians()->getValue())) * $radius);
172
    }
173
174 4
    public function __toString(): string
175
    {
176 4
        $values = [];
177 4
        foreach ($this->getCRS()->getCoordinateSystem()->getAxes() as $axis) {
178 4
            if ($axis->getName() === Axis::GEODETIC_LATITUDE) {
179 4
                $values[] = $this->latitude;
180 4
            } elseif ($axis->getName() === Axis::GEODETIC_LONGITUDE) {
181 4
                $values[] = $this->longitude;
182 1
            } elseif ($axis->getName() === Axis::ELLIPSOIDAL_HEIGHT) {
183 1
                $values[] = $this->height;
184
            } else {
185
                throw new UnknownAxisException(); // @codeCoverageIgnore
186
            }
187
        }
188
189 4
        return '(' . implode(', ', $values) . ')';
190
    }
191
192
    /**
193
     * Geographic/geocentric conversions
194
     * In applications it is often concatenated with the 3- 7- or 10-parameter transformations 9603, 9606, 9607 or
195
     * 9636 to form a geographic to geographic transformation.
196
     */
197 1
    public function geographicGeocentric(
198
        Geocentric $to
199
    ): GeocentricPoint {
200 1
        $geographicValue = new GeographicValue($this->latitude, $this->longitude, $this->height, $this->crs->getDatum());
201 1
        $asGeocentric = $geographicValue->asGeocentricValue();
202
203 1
        return GeocentricPoint::create($asGeocentric->getX(), $asGeocentric->getY(), $asGeocentric->getZ(), $to, $this->epoch);
204
    }
205
206
    /**
207
     * Coordinate Frame rotation (geog2D/geog3D domain)
208
     * Note the analogy with the Position Vector tfm (codes 9606/1037) but beware of the differences!  The Position Vector
209
     * convention is used by IAG and recommended by ISO 19111. See methods 1032/1038/9607 for similar tfms operating
210
     * between other CRS types.
211
     */
212 2
    public function coordinateFrameRotation(
213
        Geographic $to,
214
        Length $xAxisTranslation,
215
        Length $yAxisTranslation,
216
        Length $zAxisTranslation,
217
        Angle $xAxisRotation,
218
        Angle $yAxisRotation,
219
        Angle $zAxisRotation,
220
        Scale $scaleDifference
221
    ): self {
222 2
        return $this->coordinateFrameMolodenskyBadekas(
223 2
            $to,
224
            $xAxisTranslation,
225
            $yAxisTranslation,
226
            $zAxisTranslation,
227
            $xAxisRotation,
228
            $yAxisRotation,
229
            $zAxisRotation,
230
            $scaleDifference,
231 2
            new Metre(0),
232 2
            new Metre(0),
233 2
            new Metre(0)
234
        );
235
    }
236
237
    /**
238
     * Molodensky-Badekas (CF geog2D/geog3D domain)
239
     * See method codes 1034 and 1039/9636 for this operation in other coordinate domains and method code 1062/1063 for the
240
     * opposite rotation convention in geographic 2D domain.
241
     */
242 4
    public function coordinateFrameMolodenskyBadekas(
243
        Geographic $to,
244
        Length $xAxisTranslation,
245
        Length $yAxisTranslation,
246
        Length $zAxisTranslation,
247
        Angle $xAxisRotation,
248
        Angle $yAxisRotation,
249
        Angle $zAxisRotation,
250
        Scale $scaleDifference,
251
        Length $ordinate1OfEvaluationPoint,
252
        Length $ordinate2OfEvaluationPoint,
253
        Length $ordinate3OfEvaluationPoint
254
    ): self {
255 4
        $geographicValue = new GeographicValue($this->latitude, $this->longitude, $this->height, $this->crs->getDatum());
256 4
        $asGeocentric = $geographicValue->asGeocentricValue();
257
258 4
        $xs = $asGeocentric->getX()->asMetres()->getValue();
259 4
        $ys = $asGeocentric->getY()->asMetres()->getValue();
260 4
        $zs = $asGeocentric->getZ()->asMetres()->getValue();
261 4
        $tx = $xAxisTranslation->asMetres()->getValue();
262 4
        $ty = $yAxisTranslation->asMetres()->getValue();
263 4
        $tz = $zAxisTranslation->asMetres()->getValue();
264 4
        $rx = $xAxisRotation->asRadians()->getValue();
265 4
        $ry = $yAxisRotation->asRadians()->getValue();
266 4
        $rz = $zAxisRotation->asRadians()->getValue();
267 4
        $M = 1 + $scaleDifference->asUnity()->getValue();
268 4
        $xp = $ordinate1OfEvaluationPoint->asMetres()->getValue();
269 4
        $yp = $ordinate2OfEvaluationPoint->asMetres()->getValue();
270 4
        $zp = $ordinate3OfEvaluationPoint->asMetres()->getValue();
271
272 4
        $xt = $M * ((($xs - $xp) * 1) + (($ys - $yp) * $rz) + (($zs - $zp) * -$ry)) + $tx + $xp;
273 4
        $yt = $M * ((($xs - $xp) * -$rz) + (($ys - $yp) * 1) + (($zs - $zp) * $rx)) + $ty + $yp;
274 4
        $zt = $M * ((($xs - $xp) * $ry) + (($ys - $yp) * -$rx) + (($zs - $zp) * 1)) + $tz + $zp;
275 4
        $newGeocentric = new GeocentricValue(new Metre($xt), new Metre($yt), new Metre($zt), $to->getDatum());
276 4
        $newGeographic = $newGeocentric->asGeographicValue();
277
278 4
        return static::create($newGeographic->getLatitude(), $newGeographic->getLongitude(), $to instanceof Geographic3D ? $newGeographic->getHeight() : null, $to, $this->epoch);
279
    }
280
281
    /**
282
     * Position Vector transformation (geog2D/geog3D domain)
283
     * Note the analogy with the Coordinate Frame rotation (code 9607/1038) but beware of the differences!  The Position
284
     * Vector convention is used by IAG and recommended by ISO 19111. See methods 1033/1037/9606 for similar tfms
285
     * operating between other CRS types.
286
     */
287 4
    public function positionVectorTransformation(
288
        Geographic $to,
289
        Length $xAxisTranslation,
290
        Length $yAxisTranslation,
291
        Length $zAxisTranslation,
292
        Angle $xAxisRotation,
293
        Angle $yAxisRotation,
294
        Angle $zAxisRotation,
295
        Scale $scaleDifference
296
    ): self {
297 4
        return $this->positionVectorMolodenskyBadekas(
298 4
            $to,
299
            $xAxisTranslation,
300
            $yAxisTranslation,
301
            $zAxisTranslation,
302
            $xAxisRotation,
303
            $yAxisRotation,
304
            $zAxisRotation,
305
            $scaleDifference,
306 4
            new Metre(0),
307 4
            new Metre(0),
308 4
            new Metre(0)
309
        );
310
    }
311
312
    /**
313
     * Molodensky-Badekas (PV geog2D/geog3D domain)
314
     * See method codes 1061 and 1062/1063 for this operation in other coordinate domains and method code 1039/9636 for opposite
315
     * rotation in geographic 2D/3D domain.
316
     */
317 6
    public function positionVectorMolodenskyBadekas(
318
        Geographic $to,
319
        Length $xAxisTranslation,
320
        Length $yAxisTranslation,
321
        Length $zAxisTranslation,
322
        Angle $xAxisRotation,
323
        Angle $yAxisRotation,
324
        Angle $zAxisRotation,
325
        Scale $scaleDifference,
326
        Length $ordinate1OfEvaluationPoint,
327
        Length $ordinate2OfEvaluationPoint,
328
        Length $ordinate3OfEvaluationPoint
329
    ): self {
330 6
        $geographicValue = new GeographicValue($this->latitude, $this->longitude, $this->height, $this->crs->getDatum());
331 6
        $asGeocentric = $geographicValue->asGeocentricValue();
332
333 6
        $xs = $asGeocentric->getX()->asMetres()->getValue();
334 6
        $ys = $asGeocentric->getY()->asMetres()->getValue();
335 6
        $zs = $asGeocentric->getZ()->asMetres()->getValue();
336 6
        $tx = $xAxisTranslation->asMetres()->getValue();
337 6
        $ty = $yAxisTranslation->asMetres()->getValue();
338 6
        $tz = $zAxisTranslation->asMetres()->getValue();
339 6
        $rx = $xAxisRotation->asRadians()->getValue();
340 6
        $ry = $yAxisRotation->asRadians()->getValue();
341 6
        $rz = $zAxisRotation->asRadians()->getValue();
342 6
        $M = 1 + $scaleDifference->asUnity()->getValue();
343 6
        $xp = $ordinate1OfEvaluationPoint->asMetres()->getValue();
344 6
        $yp = $ordinate2OfEvaluationPoint->asMetres()->getValue();
345 6
        $zp = $ordinate3OfEvaluationPoint->asMetres()->getValue();
346
347 6
        $xt = $M * ((($xs - $xp) * 1) + (($ys - $yp) * -$rz) + (($zs - $zp) * $ry)) + $tx + $xp;
348 6
        $yt = $M * ((($xs - $xp) * $rz) + (($ys - $yp) * 1) + (($zs - $zp) * -$rx)) + $ty + $yp;
349 6
        $zt = $M * ((($xs - $xp) * -$ry) + (($ys - $yp) * $rx) + (($zs - $zp) * 1)) + $tz + $zp;
350 6
        $newGeocentric = new GeocentricValue(new Metre($xt), new Metre($yt), new Metre($zt), $to->getDatum());
351 6
        $newGeographic = $newGeocentric->asGeographicValue();
352
353 6
        return static::create($newGeographic->getLatitude(), $newGeographic->getLongitude(), $to instanceof Geographic3D ? $newGeographic->getHeight() : null, $to, $this->epoch);
354
    }
355
356
    /**
357
     * Geocentric translations
358
     * This method allows calculation of geocentric coords in the target system by adding the parameter values to the
359
     * corresponding coordinates of the point in the source system. See methods 1031 and 1035 for similar tfms
360
     * operating between other CRSs types.
361
     */
362 1
    public function geocentricTranslation(
363
        Geographic $to,
364
        Length $xAxisTranslation,
365
        Length $yAxisTranslation,
366
        Length $zAxisTranslation
367
    ): self {
368 1
        return $this->positionVectorTransformation(
369 1
            $to,
370
            $xAxisTranslation,
371
            $yAxisTranslation,
372
            $zAxisTranslation,
373 1
            new Radian(0),
374 1
            new Radian(0),
375 1
            new Radian(0),
376 1
            new Unity(0)
377
        );
378
    }
379
380
    /**
381
     * Abridged Molodensky
382
     * This transformation is a truncated Taylor series expansion of a transformation between two geographic coordinate
383
     * systems, modelled as a set of geocentric translations.
384
     */
385 2
    public function abridgedMolodensky(
386
        Geographic $to,
387
        Length $xAxisTranslation,
388
        Length $yAxisTranslation,
389
        Length $zAxisTranslation,
390
        Length $differenceInSemiMajorAxis,
391
        Scale $differenceInFlattening
392
    ): self {
393 2
        $latitude = $this->latitude->asRadians()->getValue();
394 2
        $longitude = $this->longitude->asRadians()->getValue();
395 2
        $fromHeight = $this->height ? $this->height->asMetres()->getValue() : 0;
396 2
        $tx = $xAxisTranslation->asMetres()->getValue();
397 2
        $ty = $yAxisTranslation->asMetres()->getValue();
398 2
        $tz = $zAxisTranslation->asMetres()->getValue();
399 2
        $da = $differenceInSemiMajorAxis->asMetres()->getValue();
400 2
        $df = $differenceInFlattening->asUnity()->getValue();
401
402 2
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
403 2
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
404
405 2
        $rho = $a * (1 - $e2) / (1 - $e2 * sin($latitude) ** 2) ** (3 / 2);
406 2
        $nu = $a / sqrt(1 - $e2 * (sin($latitude) ** 2));
407
408 2
        $f = $this->crs->getDatum()->getEllipsoid()->getInverseFlattening();
409
410 2
        $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()));
411 2
        $dLongitude = (-$tx * sin($longitude) + $ty * cos($longitude)) / (($nu * cos($latitude)) * sin((new ArcSecond(1))->asRadians()->getValue()));
412 2
        $dHeight = ($tx * cos($latitude) * cos($longitude)) + ($ty * cos($latitude) * sin($longitude)) + ($tz * sin($latitude)) + (($a * $df + $f * $da) * (sin($latitude) ** 2)) - $da;
413
414 2
        $toLatitude = $latitude + (new ArcSecond($dLatitude))->asRadians()->getValue();
415 2
        $toLongitude = $longitude + (new ArcSecond($dLongitude))->asRadians()->getValue();
416 2
        $toHeight = $fromHeight + $dHeight;
417
418 2
        return static::create(new Radian($toLatitude), new Radian($toLongitude), $to instanceof Geographic3D ? new Metre($toHeight) : null, $to, $this->epoch);
419
    }
420
421
    /**
422
     * Molodensky
423
     * See Abridged Molodensky.
424
     */
425 2
    public function molodensky(
426
        Geographic $to,
427
        Length $xAxisTranslation,
428
        Length $yAxisTranslation,
429
        Length $zAxisTranslation,
430
        Length $differenceInSemiMajorAxis,
431
        Scale $differenceInFlattening
432
    ): self {
433 2
        $latitude = $this->latitude->asRadians()->getValue();
434 2
        $longitude = $this->longitude->asRadians()->getValue();
435 2
        $fromHeight = $this->height ? $this->height->asMetres()->getValue() : 0;
436 2
        $tx = $xAxisTranslation->asMetres()->getValue();
437 2
        $ty = $yAxisTranslation->asMetres()->getValue();
438 2
        $tz = $zAxisTranslation->asMetres()->getValue();
439 2
        $da = $differenceInSemiMajorAxis->asMetres()->getValue();
440 2
        $df = $differenceInFlattening->asUnity()->getValue();
441
442 2
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
443 2
        $b = $this->crs->getDatum()->getEllipsoid()->getSemiMinorAxis()->asMetres()->getValue();
444 2
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
445
446 2
        $rho = $a * (1 - $e2) / (1 - $e2 * sin($latitude) ** 2) ** (3 / 2);
447 2
        $nu = $a / sqrt(1 - $e2 * (sin($latitude) ** 2));
448
449 2
        $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...
450
451 2
        $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()));
452 2
        $dLongitude = (-$tx * sin($longitude) + $ty * cos($longitude)) / ((($nu + $fromHeight) * cos($latitude)) * sin((new ArcSecond(1))->asRadians()->getValue()));
453 2
        $dHeight = ($tx * cos($latitude) * cos($longitude)) + ($ty * cos($latitude) * sin($longitude)) + ($tz * sin($latitude)) - $da * $a / $nu + $df * $b / $a * $nu * sin($latitude) ** 2;
454
455 2
        $toLatitude = $latitude + (new ArcSecond($dLatitude))->asRadians()->getValue();
456 2
        $toLongitude = $longitude + (new ArcSecond($dLongitude))->asRadians()->getValue();
457 2
        $toHeight = $fromHeight + $dHeight;
458
459 2
        return static::create(new Radian($toLatitude), new Radian($toLongitude), $to instanceof Geographic3D ? new Metre($toHeight) : null, $to, $this->epoch);
460
    }
461
462
    /**
463
     * Albers Equal Area.
464
     */
465 2
    public function albersEqualArea(
466
        Projected $to,
467
        Angle $latitudeOfFalseOrigin,
468
        Angle $longitudeOfFalseOrigin,
469
        Angle $latitudeOf1stStandardParallel,
470
        Angle $latitudeOf2ndStandardParallel,
471
        Length $eastingAtFalseOrigin,
472
        Length $northingAtFalseOrigin
473
    ): ProjectedPoint {
474 2
        $latitude = $this->latitude->asRadians()->getValue();
475 2
        $longitude = $this->longitude->asRadians()->getValue();
476 2
        $phiOrigin = $latitudeOfFalseOrigin->asRadians()->getValue();
477 2
        $phi1 = $latitudeOf1stStandardParallel->asRadians()->getValue();
478 2
        $phi2 = $latitudeOf2ndStandardParallel->asRadians()->getValue();
479 2
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
480 2
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
481 2
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
482
483 2
        $centralMeridianFirstParallel = cos($phi1) / sqrt(1 - ($e2 * sin($phi1) ** 2));
484 2
        $centralMeridianSecondParallel = cos($phi2) / sqrt(1 - ($e2 * sin($phi2) ** 2));
485
486 2
        $alpha = (1 - $e2) * (sin($latitude) / (1 - $e2 * sin($latitude) ** 2) - (1 / 2 / $e) * log((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))));
487 2
        $alphaOrigin = (1 - $e2) * (sin($phiOrigin) / (1 - $e2 * sin($phiOrigin) ** 2) - (1 / 2 / $e) * log((1 - $e * sin($phiOrigin)) / (1 + $e * sin($phiOrigin))));
488 2
        $alphaFirstParallel = (1 - $e2) * (sin($phi1) / (1 - $e2 * sin($phi1) ** 2) - (1 / 2 / $e) * log((1 - $e * sin($phi1)) / (1 + $e * sin($phi1))));
489 2
        $alphaSecondParallel = (1 - $e2) * (sin($phi2) / (1 - $e2 * sin($phi2) ** 2) - (1 / 2 / $e) * log((1 - $e * sin($phi2)) / (1 + $e * sin($phi2))));
490
491 2
        $n = ($centralMeridianFirstParallel ** 2 - $centralMeridianSecondParallel ** 2) / ($alphaSecondParallel - $alphaFirstParallel);
492 2
        $C = $centralMeridianFirstParallel ** 2 + $n * $alphaFirstParallel;
493 2
        $theta = $n * ($longitude - $longitudeOfFalseOrigin->asRadians()->getValue());
494 2
        $rho = $a * sqrt($C - $n * $alpha) / $n;
495 2
        $rhoOrigin = ($a * sqrt($C - $n * $alphaOrigin)) / $n;
496
497 2
        $easting = $eastingAtFalseOrigin->asMetres()->getValue() + ($rho * sin($theta));
498 2
        $northing = $northingAtFalseOrigin->asMetres()->getValue() + $rhoOrigin - ($rho * cos($theta));
499
500 2
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
501
    }
502
503
    /**
504
     * American Polyconic.
505
     */
506 1
    public function americanPolyconic(
507
        Projected $to,
508
        Angle $latitudeOfNaturalOrigin,
509
        Angle $longitudeOfNaturalOrigin,
510
        Length $falseEasting,
511
        Length $falseNorthing
512
    ): ProjectedPoint {
513 1
        $latitude = $this->latitude->asRadians()->getValue();
514 1
        $longitude = $this->longitude->asRadians()->getValue();
515 1
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
516 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
517 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
518 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
519 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
520 1
        $e4 = $e ** 4;
521 1
        $e6 = $e ** 6;
522
523 1
        $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));
524 1
        $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));
525
526 1
        if ($latitude === 0.0) {
0 ignored issues
show
introduced by
The condition $latitude === 0.0 is always false.
Loading history...
527
            $easting = $falseEasting->asMetres()->getValue() + $a * ($longitude - $longitudeOrigin);
528
            $northing = $falseNorthing->asMetres()->getValue() - $MO;
529
        } else {
530 1
            $L = ($longitude - $longitudeOrigin) * sin($latitude);
531 1
            $nu = $a / sqrt(1 - $e2 * sin($latitude) ** 2);
532
533 1
            $easting = $falseEasting->asMetres()->getValue() + $nu * 1 / tan($latitude) * sin($L);
534 1
            $northing = $falseNorthing->asMetres()->getValue() + $M - $MO + $nu * 1 / tan($latitude) * (1 - cos($L));
535
        }
536
537 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
538
    }
539
540
    /**
541
     * Bonne.
542
     */
543 1
    public function bonne(
544
        Projected $to,
545
        Angle $latitudeOfNaturalOrigin,
546
        Angle $longitudeOfNaturalOrigin,
547
        Length $falseEasting,
548
        Length $falseNorthing
549
    ): ProjectedPoint {
550 1
        $latitude = $this->latitude->asRadians()->getValue();
551 1
        $longitude = $this->longitude->asRadians()->getValue();
552 1
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
553 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
554 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
555 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
556 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
557 1
        $e4 = $e ** 4;
558 1
        $e6 = $e ** 6;
559
560 1
        $m = cos($latitude) / sqrt(1 - $e2 * sin($latitude) ** 2);
561 1
        $mO = cos($latitudeOrigin) / sqrt(1 - $e2 * sin($latitudeOrigin) ** 2);
562
563 1
        $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));
564 1
        $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));
565
566 1
        $rho = $a * $mO / sin($latitudeOrigin) + $MO - $M;
567 1
        $tau = $a * $m * ($longitude - $longitudeOrigin) / $rho;
568
569 1
        $easting = $falseEasting->asMetres()->getValue() + ($rho * sin($tau));
570 1
        $northing = $falseNorthing->asMetres()->getValue() + (($a * $mO / sin($latitudeOrigin) - $rho * cos($tau)));
571
572 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
573
    }
574
575
    /**
576
     * Bonne South Orientated.
577
     */
578 1
    public function bonneSouthOrientated(
579
        Projected $to,
580
        Angle $latitudeOfNaturalOrigin,
581
        Angle $longitudeOfNaturalOrigin,
582
        Length $falseEasting,
583
        Length $falseNorthing
584
    ): ProjectedPoint {
585 1
        $latitude = $this->latitude->asRadians()->getValue();
586 1
        $longitude = $this->longitude->asRadians()->getValue();
587 1
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
588 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
589 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
590 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
591 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
592 1
        $e4 = $e ** 4;
593 1
        $e6 = $e ** 6;
594
595 1
        $m = cos($latitude) / sqrt(1 - $e2 * sin($latitude) ** 2);
596 1
        $mO = cos($latitudeOrigin) / sqrt(1 - $e2 * sin($latitudeOrigin) ** 2);
597
598 1
        $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 1
        $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 1
        $rho = $a * $mO / sin($latitudeOrigin) + $MO - $M;
602 1
        $tau = $a * $m * ($longitude - $longitudeOrigin) / $rho;
603
604 1
        $westing = $falseEasting->asMetres()->getValue() - ($rho * sin($tau));
605 1
        $southing = $falseNorthing->asMetres()->getValue() - (($a * $mO / sin($latitudeOrigin) - $rho * cos($tau)));
606
607 1
        return ProjectedPoint::create(new Metre(-$westing), new Metre(-$southing), new Metre($westing), new Metre($southing), $to, $this->epoch);
608
    }
609
610
    /**
611
     * Cassini-Soldner.
612
     */
613 1
    public function cassiniSoldner(
614
        Projected $to,
615
        Angle $latitudeOfNaturalOrigin,
616
        Angle $longitudeOfNaturalOrigin,
617
        Length $falseEasting,
618
        Length $falseNorthing
619
    ): ProjectedPoint {
620 1
        $latitude = $this->latitude->asRadians()->getValue();
621 1
        $longitude = $this->longitude->asRadians()->getValue();
622 1
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
623 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
624 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
625 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
626 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
627 1
        $e4 = $e ** 4;
628 1
        $e6 = $e ** 6;
629
630 1
        $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));
631 1
        $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));
632
633 1
        $A = ($longitude - $longitudeOrigin) * cos($latitude);
634 1
        $T = tan($latitude) ** 2;
635 1
        $C = $e2 * cos($latitude) ** 2 / (1 - $e2);
636 1
        $nu = $a / sqrt(1 - $e2 * (sin($latitude) ** 2));
637 1
        $X = $M - $MO + $nu * tan($latitude) * ($A ** 2 / 2 + (5 - $T + 6 * $C) * $A ** 4 / 24);
638
639 1
        $easting = $falseEasting->asMetres()->getValue() + $nu * ($A - $T * $A ** 3 / 6 - (8 - $T + 8 * $C) * $T * $A ** 5 / 120);
640 1
        $northing = $falseNorthing->asMetres()->getValue() + $X;
641
642 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
643
    }
644
645
    /**
646
     * Hyperbolic Cassini-Soldner.
647
     */
648 2
    public function hyperbolicCassiniSoldner(
649
        Projected $to,
650
        Angle $latitudeOfNaturalOrigin,
651
        Angle $longitudeOfNaturalOrigin,
652
        Length $falseEasting,
653
        Length $falseNorthing
654
    ): ProjectedPoint {
655 2
        $latitude = $this->latitude->asRadians()->getValue();
656 2
        $longitude = $this->longitude->asRadians()->getValue();
657 2
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
658 2
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
659 2
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
660 2
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
661 2
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
662 2
        $e4 = $e ** 4;
663 2
        $e6 = $e ** 6;
664
665 2
        $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));
666 2
        $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));
667
668 2
        $A = ($longitude - $longitudeOrigin) * cos($latitude);
669 2
        $T = tan($latitude) ** 2;
670 2
        $C = $e2 * cos($latitude) ** 2 / (1 - $e2);
671 2
        $nu = $a / sqrt(1 - $e2 * (sin($latitude) ** 2));
672 2
        $rho = $a * (1 - $e2) / (1 - $e2 * sin($latitude) ** 2) ** (3 / 2);
673 2
        $X = $M - $MO + $nu * tan($latitude) * ($A ** 2 / 2 + (5 - $T + 6 * $C) * $A ** 4 / 24);
674
675 2
        $easting = $falseEasting->asMetres()->getValue() + $nu * ($A - $T * $A ** 3 / 6 - (8 - $T + 8 * $C) * $T * $A ** 5 / 120);
676 2
        $northing = $falseNorthing->asMetres()->getValue() + $X - ($X ** 3 / (6 * $rho * $nu));
677
678 2
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
679
    }
680
681
    /**
682
     * Colombia Urban.
683
     */
684 1
    public function columbiaUrban(
685
        Projected $to,
686
        Angle $latitudeOfNaturalOrigin,
687
        Angle $longitudeOfNaturalOrigin,
688
        Length $falseEasting,
689
        Length $falseNorthing,
690
        Length $projectionPlaneOriginHeight
691
    ): ProjectedPoint {
692 1
        $latitude = $this->latitude->asRadians()->getValue();
693 1
        $longitude = $this->longitude->asRadians()->getValue();
694 1
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
695 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
696 1
        $heightOrigin = $projectionPlaneOriginHeight->asMetres()->getValue();
697 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
698 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
699
700 1
        $rho = $a * (1 - $e2) / (1 - $e2 * sin($latitude) ** 2) ** (3 / 2);
0 ignored issues
show
Unused Code introduced by
The assignment to $rho is dead and can be removed.
Loading history...
701 1
        $rhoOrigin = $a * (1 - $e2) / (1 - $e2 * sin($latitudeOrigin) ** 2) ** (3 / 2);
702 1
        $rhoMid = $a * (1 - $e2) / (1 - $e2 * sin(($latitude + $latitudeOrigin) / 2) ** 2) ** (3 / 2);
703
704 1
        $nu = $a / sqrt(1 - $e2 * (sin($latitude) ** 2));
705 1
        $nuOrigin = $a / sqrt(1 - $e2 * (sin($latitudeOrigin) ** 2));
706
707 1
        $A = 1 + $heightOrigin / $nuOrigin;
708 1
        $B = tan($latitudeOrigin) / (2 * $rhoOrigin * $nuOrigin);
709 1
        $G = 1 + $heightOrigin / $rhoMid;
710
711 1
        $easting = $falseEasting->asMetres()->getValue() + $A * $nu * cos($latitude) * ($longitude - $longitudeOrigin);
712 1
        $northing = $falseNorthing->asMetres()->getValue() + $G * $rhoOrigin * (($latitude - $latitudeOrigin) + ($B * ($longitude - $longitudeOrigin) ** 2 * $nu ** 2 * cos($latitude) ** 2));
713
714 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
715
    }
716
717
    /**
718
     * Equal Earth.
719
     */
720 1
    public function equalEarth(
721
        Projected $to,
722
        Angle $longitudeOfNaturalOrigin,
723
        Length $falseEasting,
724
        Length $falseNorthing
725
    ): ProjectedPoint {
726 1
        $latitude = $this->latitude->asRadians()->getValue();
727 1
        $longitude = $this->longitude->asRadians()->getValue();
728 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
729 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
730 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
731 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
732
733 1
        $q = (1 - $e2) * ((sin($latitude) / (1 - $e2 * sin($latitude) ** 2)) - (1 / (2 * $e) * log((1 - $e * sin($latitude)) / (1 + $e * sin($latitude)))));
734 1
        $qP = (1 - $e2) * ((1 / (1 - $e2)) - (1 / (2 * $e) * log((1 - $e) / (1 + $e))));
735 1
        $beta = self::asin($q / $qP);
736 1
        $theta = self::asin(sin($beta) * sqrt(3) / 2);
737 1
        $Rq = $a * sqrt($qP / 2);
738
739 1
        $easting = $falseEasting->asMetres()->getValue() + ($Rq * 2 * ($longitude - $longitudeOrigin) * cos($theta)) / (sqrt(3) * (1.340264 - 0.243318 * $theta ** 2 + $theta ** 6 * (0.006251 + 0.034164 * $theta ** 2)));
740 1
        $northing = $falseNorthing->asMetres()->getValue() + $Rq * $theta * (1.340264 - 0.081106 * $theta ** 2 + $theta ** 6 * (0.000893 + 0.003796 * $theta ** 2));
741
742 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
743
    }
744
745
    /**
746
     * Equidistant Cylindrical
747
     * See method code 1029 for spherical development. See also Pseudo Plate Carree, method code 9825.
748
     */
749 1
    public function equidistantCylindrical(
750
        Projected $to,
751
        Angle $latitudeOf1stStandardParallel,
752
        Angle $longitudeOfNaturalOrigin,
753
        Length $falseEasting,
754
        Length $falseNorthing
755
    ): ProjectedPoint {
756 1
        $latitude = $this->latitude->asRadians()->getValue();
757 1
        $longitude = $this->longitude->asRadians()->getValue();
758 1
        $latitudeFirstParallel = $latitudeOf1stStandardParallel->asRadians()->getValue();
759 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
760 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
761 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
762 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
763 1
        $e4 = $e ** 4;
764 1
        $e6 = $e ** 6;
765 1
        $e8 = $e ** 8;
766 1
        $e10 = $e ** 10;
767 1
        $e12 = $e ** 12;
768 1
        $e14 = $e ** 14;
769
770 1
        $nu1 = $a / sqrt(1 - $e2 * sin($latitudeFirstParallel) ** 2);
771
772
        $M = $a * (
773 1
            (1 - 1 / 4 * $e2 - 3 / 64 * $e4 - 5 / 256 * $e6 - 175 / 16384 * $e8 - 441 / 65536 * $e10 - 4851 / 1048576 * $e12 - 14157 / 4194304 * $e14) * $latitude +
774 1
            (-3 / 8 * $e2 - 3 / 32 * $e4 - 45 / 1024 * $e6 - 105 / 4096 * $e8 - 2205 / 131072 * $e10 - 6237 / 524288 * $e12 - 297297 / 33554432 * $e14) * sin(2 * $latitude) +
775 1
            (15 / 256 * $e4 + 45 / 1024 * $e ** 6 + 525 / 16384 * $e ** 8 + 1575 / 65536 * $e10 + 155925 / 8388608 * $e12 + 495495 / 33554432 * $e14) * sin(4 * $latitude) +
776 1
            (-35 / 3072 * $e6 - 175 / 12288 * $e8 - 3675 / 262144 * $e10 - 13475 / 1048576 * $e12 - 385385 / 33554432 * $e14) * sin(6 * $latitude) +
777 1
            (315 / 131072 * $e8 + 2205 / 524288 * $e10 + 43659 / 8388608 * $e12 + 189189 / 33554432 * $e14) * sin(8 * $latitude) +
778 1
            (-693 / 1310720 * $e10 - 6537 / 5242880 * $e12 - 297297 / 167772160 * $e14) * sin(10 * $latitude) +
779 1
            (1001 / 8388608 * $e12 + 11011 / 33554432 * $e14) * sin(12 * $latitude) +
780 1
            (-6435 / 234881024 * $e ** 14) * sin(14 * $latitude)
781
        );
782
783 1
        $easting = $falseEasting->asMetres()->getValue() + $nu1 * cos($latitudeFirstParallel) * ($longitude - $longitudeOrigin);
784 1
        $northing = $falseNorthing->asMetres()->getValue() + $M;
785
786 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
787
    }
788
789
    /**
790
     * Guam Projection
791
     * Simplified form of Oblique Azimuthal Equidistant projection method.
792
     */
793 1
    public function guamProjection(
794
        Projected $to,
795
        Angle $latitudeOfNaturalOrigin,
796
        Angle $longitudeOfNaturalOrigin,
797
        Length $falseEasting,
798
        Length $falseNorthing
799
    ): ProjectedPoint {
800 1
        $latitude = $this->latitude->asRadians()->getValue();
801 1
        $longitude = $this->longitude->asRadians()->getValue();
802 1
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
803 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
804 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
805 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
806 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
807 1
        $e4 = $e ** 4;
808 1
        $e6 = $e ** 6;
809
810 1
        $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));
811 1
        $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));
812 1
        $x = ($a * ($longitude - $longitudeOrigin) * cos($latitude)) / sqrt(1 - $e2 * sin($latitude) ** 2);
813
814 1
        $easting = $falseEasting->asMetres()->getValue() + $x;
815 1
        $northing = $falseNorthing->asMetres()->getValue() + $M - $MO + ($x ** 2 * tan($latitude) * sqrt(1 - $e2 * sin($latitude) ** 2) / (2 * $a));
816
817 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
818
    }
819
820
    /**
821
     * Krovak.
822
     */
823 4
    public function krovak(
824
        Projected $to,
825
        Angle $latitudeOfProjectionCentre,
826
        Angle $longitudeOfOrigin,
827
        Angle $coLatitudeOfConeAxis,
828
        Angle $latitudeOfPseudoStandardParallel,
829
        Scale $scaleFactorOnPseudoStandardParallel,
830
        Length $falseEasting,
831
        Length $falseNorthing
832
    ): ProjectedPoint {
833 4
        $longitudeOffset = $to->getDatum()->getPrimeMeridian()->getGreenwichLongitude()->asRadians()->getValue() - $this->getCRS()->getDatum()->getPrimeMeridian()->getGreenwichLongitude()->asRadians()->getValue();
834 4
        $latitude = $this->latitude->asRadians()->getValue();
835 4
        $longitude = $this->longitude->asRadians()->getValue() - $longitudeOffset;
836 4
        $latitudeC = $latitudeOfProjectionCentre->asRadians()->getValue();
837 4
        $longitudeO = $longitudeOfOrigin->asRadians()->getValue();
838 4
        $alphaC = $coLatitudeOfConeAxis->asRadians()->getValue();
839 4
        $latitudeP = $latitudeOfPseudoStandardParallel->asRadians()->getValue();
840 4
        $kP = $scaleFactorOnPseudoStandardParallel->asUnity()->getValue();
841 4
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
842 4
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
843 4
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
844
845 4
        $A = $a * sqrt(1 - $e2) / (1 - $e2 * sin($latitudeC) ** 2);
846 4
        $B = sqrt(1 + $e2 * cos($latitudeC) ** 4 / (1 - $e2));
847 4
        $upsilonO = self::asin(sin($latitudeC) / $B);
848 4
        $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);
849 4
        $n = sin($latitudeP);
850 4
        $rO = $kP * $A / tan($latitudeP);
851
852 4
        $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);
853 4
        $V = $B * ($longitudeO - $longitude);
854 4
        $T = self::asin(cos($alphaC) * sin($U) + sin($alphaC) * cos($U) * cos($V));
855 4
        $D = atan2(cos($U) * sin($V) / cos($T), ((cos($alphaC) * sin($T) - sin($U)) / (sin($alphaC) * cos($T))));
856 4
        $theta = $n * $D;
857 4
        $r = $rO * tan(M_PI / 4 + $latitudeP / 2) ** $n / tan($T / 2 + M_PI / 4) ** $n;
858 4
        $X = $r * cos($theta);
859 4
        $Y = $r * sin($theta);
860
861 4
        $westing = $Y + $falseEasting->asMetres()->getValue();
862 4
        $southing = $X + $falseNorthing->asMetres()->getValue();
863
864 4
        return ProjectedPoint::create(new Metre(-$westing), new Metre(-$southing), new Metre($westing), new Metre($southing), $to, $this->epoch);
865
    }
866
867
    /**
868
     * Krovak Modified
869
     * Incorporates a polynomial transformation which is defined to be exact and for practical purposes is considered
870
     * to be a map projection.
871
     */
872 2
    public function krovakModified(
873
        Projected $to,
874
        Angle $latitudeOfProjectionCentre,
875
        Angle $longitudeOfOrigin,
876
        Angle $coLatitudeOfConeAxis,
877
        Angle $latitudeOfPseudoStandardParallel,
878
        Scale $scaleFactorOnPseudoStandardParallel,
879
        Length $falseEasting,
880
        Length $falseNorthing,
881
        Length $ordinate1OfEvaluationPoint,
882
        Length $ordinate2OfEvaluationPoint,
883
        Coefficient $C1,
884
        Coefficient $C2,
885
        Coefficient $C3,
886
        Coefficient $C4,
887
        Coefficient $C5,
888
        Coefficient $C6,
889
        Coefficient $C7,
890
        Coefficient $C8,
891
        Coefficient $C9,
892
        Coefficient $C10
893
    ): ProjectedPoint {
894 2
        $asKrovak = $this->krovak($to, $latitudeOfProjectionCentre, $longitudeOfOrigin, $coLatitudeOfConeAxis, $latitudeOfPseudoStandardParallel, $scaleFactorOnPseudoStandardParallel, new Metre(0), new Metre(0));
895
896 2
        $westing = $asKrovak->getWesting()->asMetres()->getValue();
897 2
        $southing = $asKrovak->getSouthing()->asMetres()->getValue();
898 2
        $c1 = $C1->asUnity()->getValue();
899 2
        $c2 = $C2->asUnity()->getValue();
900 2
        $c3 = $C3->asUnity()->getValue();
901 2
        $c4 = $C4->asUnity()->getValue();
902 2
        $c5 = $C5->asUnity()->getValue();
903 2
        $c6 = $C6->asUnity()->getValue();
904 2
        $c7 = $C7->asUnity()->getValue();
905 2
        $c8 = $C8->asUnity()->getValue();
906 2
        $c9 = $C9->asUnity()->getValue();
907 2
        $c10 = $C10->asUnity()->getValue();
908
909 2
        $Xr = $southing - $ordinate1OfEvaluationPoint->asMetres()->getValue();
910 2
        $Yr = $westing - $ordinate2OfEvaluationPoint->asMetres()->getValue();
911
912 2
        $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);
913 2
        $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);
914
915 2
        $westing += $falseEasting->asMetres()->getValue() - $dY;
916 2
        $southing += $falseNorthing->asMetres()->getValue() - $dX;
917
918 2
        return ProjectedPoint::create(new Metre(-$westing), new Metre(-$southing), new Metre($westing), new Metre($southing), $to, $this->epoch);
919
    }
920
921
    /**
922
     * Lambert Azimuthal Equal Area
923
     * This is the ellipsoidal form of the projection.
924
     */
925 1
    public function lambertAzimuthalEqualArea(
926
        Projected $to,
927
        Angle $latitudeOfNaturalOrigin,
928
        Angle $longitudeOfNaturalOrigin,
929
        Length $falseEasting,
930
        Length $falseNorthing
931
    ): ProjectedPoint {
932 1
        $latitude = $this->latitude->asRadians()->getValue();
933 1
        $longitude = $this->longitude->asRadians()->getValue();
934 1
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
935 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
936 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
937 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
938 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
939
940 1
        $q = (1 - $e2) * ((sin($latitude) / (1 - $e2 * sin($latitude) ** 2)) - ((1 / (2 * $e)) * log((1 - $e * sin($latitude)) / (1 + $e * sin($latitude)))));
941 1
        $qO = (1 - $e2) * ((sin($latitudeOrigin) / (1 - $e2 * sin($latitudeOrigin) ** 2)) - ((1 / (2 * $e)) * log((1 - $e * sin($latitudeOrigin)) / (1 + $e * sin($latitudeOrigin)))));
942 1
        $qP = (1 - $e2) * ((1 / (1 - $e2)) - ((1 / (2 * $e)) * log((1 - $e) / (1 + $e))));
943 1
        $beta = self::asin($q / $qP);
944 1
        $betaO = self::asin($qO / $qP);
945 1
        $Rq = $a * sqrt($qP / 2);
946 1
        $B = $Rq * sqrt(2 / (1 + sin($betaO) * sin($beta) + (cos($betaO) * cos($beta) * cos($longitude - $longitudeOrigin))));
947 1
        $D = $a * (cos($latitudeOrigin) / sqrt(1 - $e2 * sin($latitudeOrigin) ** 2)) / ($Rq * cos($betaO));
948
949 1
        $easting = $falseEasting->asMetres()->getValue() + (($B * $D) * (cos($beta) * sin($longitude - $longitudeOrigin)));
950 1
        $northing = $falseNorthing->asMetres()->getValue() + ($B / $D) * ((cos($betaO) * sin($beta)) - (sin($betaO) * cos($beta) * cos($longitude - $longitudeOrigin)));
951
952 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
953
    }
954
955
    /**
956
     * Lambert Azimuthal Equal Area (Spherical)
957
     * This is the spherical form of the projection.  See coordinate operation method Lambert Azimuthal Equal Area
958
     * (code 9820) for ellipsoidal form.  Differences of several tens of metres result from comparison of the two
959
     * methods.
960
     */
961 1
    public function lambertAzimuthalEqualAreaSpherical(
962
        Projected $to,
963
        Angle $latitudeOfNaturalOrigin,
964
        Angle $longitudeOfNaturalOrigin,
965
        Length $falseEasting,
966
        Length $falseNorthing
967
    ): ProjectedPoint {
968 1
        $latitude = $this->latitude->asRadians()->getValue();
969 1
        $longitude = $this->longitude->asRadians()->getValue();
970 1
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
971 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
972 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
973
974 1
        $k = sqrt(2 / (1 + sin($latitudeOrigin) * sin($latitude) + cos($latitudeOrigin) * cos($latitude) * cos($longitude - $longitudeOrigin)));
975
976 1
        $easting = $falseEasting->asMetres()->getValue() + ($a * $k * cos($latitude) * sin($longitude - $longitudeOrigin));
977 1
        $northing = $falseNorthing->asMetres()->getValue() + ($a * $k * (cos($latitudeOrigin) * sin($latitude) - sin($latitudeOrigin) * cos($latitude) * cos($longitude - $longitudeOrigin)));
978
979 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
980
    }
981
982
    /**
983
     * Lambert Conic Conformal (1SP).
984
     */
985 1
    public function lambertConicConformal1SP(
986
        Projected $to,
987
        Angle $latitudeOfNaturalOrigin,
988
        Angle $longitudeOfNaturalOrigin,
989
        Scale $scaleFactorAtNaturalOrigin,
990
        Length $falseEasting,
991
        Length $falseNorthing
992
    ): ProjectedPoint {
993 1
        $latitude = $this->latitude->asRadians()->getValue();
994 1
        $longitude = $this->longitude->asRadians()->getValue();
995 1
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
996 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
997 1
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
998 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
999 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1000 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1001
1002 1
        $mO = cos($latitudeOrigin) / sqrt(1 - $e2 * sin($latitudeOrigin) ** 2);
1003 1
        $tO = tan(M_PI / 4 - $latitudeOrigin / 2) / ((1 - $e * sin($latitudeOrigin)) / (1 + $e * sin($latitudeOrigin))) ** ($e / 2);
1004 1
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1005 1
        $n = sin($latitudeOrigin);
1006 1
        $F = $mO / ($n * $tO ** $n);
1007 1
        $rO = $a * $F * $tO ** $n * $kO;
1008 1
        $r = $a * $F * $t ** $n * $kO;
1009 1
        $theta = $n * ($longitude - $longitudeOrigin);
1010
1011 1
        $easting = $falseEasting->asMetres()->getValue() + $r * sin($theta);
1012 1
        $northing = $falseNorthing->asMetres()->getValue() + $rO - $r * cos($theta);
1013
1014 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1015
    }
1016
1017
    /**
1018
     * Lambert Conic Conformal (1SP) Variant B.
1019
     */
1020
    public function lambertConicConformal1SPVariantB(
1021
        Projected $to,
1022
        Angle $latitudeOfNaturalOrigin,
1023
        Scale $scaleFactorAtNaturalOrigin,
1024
        Angle $latitudeOfFalseOrigin,
1025
        Angle $longitudeOfFalseOrigin,
1026
        Length $eastingAtFalseOrigin,
1027
        Length $northingAtFalseOrigin
1028
    ): ProjectedPoint {
1029
        $latitude = $this->latitude->asRadians()->getValue();
1030
        $longitude = $this->longitude->asRadians()->getValue();
1031
        $latitudeNaturalOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
1032
        $latitudeFalseOrigin = $latitudeOfFalseOrigin->asRadians()->getValue();
1033
        $longitudeFalseOrigin = $longitudeOfFalseOrigin->asRadians()->getValue();
1034
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
1035
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1036
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1037
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1038
1039
        $mO = cos($latitudeNaturalOrigin) / sqrt(1 - $e2 * sin($latitudeNaturalOrigin) ** 2);
1040
        $tO = tan(M_PI / 4 - $latitudeNaturalOrigin / 2) / ((1 - $e * sin($latitudeNaturalOrigin)) / (1 + $e * sin($latitudeNaturalOrigin))) ** ($e / 2);
1041
        $tF = tan(M_PI / 4 - $latitudeFalseOrigin / 2) / ((1 - $e * sin($latitudeFalseOrigin)) / (1 + $e * sin($latitudeFalseOrigin))) ** ($e / 2);
1042
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1043
        $n = sin($latitudeNaturalOrigin);
1044
        $F = $mO / ($n * $tO ** $n);
1045
        $rF = $a * $F * $tF ** $n * $kO;
1046
        $r = $a * $F * $t ** $n * $kO;
1047
        $theta = $n * ($longitude - $longitudeFalseOrigin);
1048
1049
        $easting = $eastingAtFalseOrigin->asMetres()->getValue() + $r * sin($theta);
1050
        $northing = $northingAtFalseOrigin->asMetres()->getValue() + $rF - $r * cos($theta);
1051
1052
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1053
    }
1054
1055
    /**
1056
     * Lambert Conic Conformal (2SP Belgium)
1057
     * In 2000 this modification was replaced through use of the regular Lambert Conic Conformal (2SP) method [9802]
1058
     * with appropriately modified parameter values.
1059
     */
1060 1
    public function lambertConicConformal2SPBelgium(
1061
        Projected $to,
1062
        Angle $latitudeOfFalseOrigin,
1063
        Angle $longitudeOfFalseOrigin,
1064
        Angle $latitudeOf1stStandardParallel,
1065
        Angle $latitudeOf2ndStandardParallel,
1066
        Length $eastingAtFalseOrigin,
1067
        Length $northingAtFalseOrigin
1068
    ): ProjectedPoint {
1069 1
        $latitude = $this->latitude->asRadians()->getValue();
1070 1
        $longitude = $this->longitude->asRadians()->getValue();
1071 1
        $lambdaF = $longitudeOfFalseOrigin->asRadians()->getValue();
1072 1
        $phiF = $latitudeOfFalseOrigin->asRadians()->getValue();
1073 1
        $phi1 = $latitudeOf1stStandardParallel->asRadians()->getValue();
1074 1
        $phi2 = $latitudeOf2ndStandardParallel->asRadians()->getValue();
1075 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1076 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1077 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1078
1079 1
        $m1 = cos($phi1) / sqrt(1 - $e2 * sin($phi1) ** 2);
1080 1
        $m2 = cos($phi2) / sqrt(1 - $e2 * sin($phi2) ** 2);
1081 1
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1082 1
        $t1 = tan(M_PI / 4 - $phi1 / 2) / ((1 - $e * sin($phi1)) / (1 + $e * sin($phi1))) ** ($e / 2);
1083 1
        $t2 = tan(M_PI / 4 - $phi2 / 2) / ((1 - $e * sin($phi2)) / (1 + $e * sin($phi2))) ** ($e / 2);
1084 1
        $tF = tan(M_PI / 4 - $phiF / 2) / ((1 - $e * sin($phiF)) / (1 + $e * sin($phiF))) ** ($e / 2);
1085 1
        $n = (log($m1) - log($m2)) / (log($t1) - log($t2));
1086 1
        $F = $m1 / ($n * $t1 ** $n);
1087 1
        $r = $a * $F * $t ** $n;
1088 1
        $rF = $a * $F * $tF ** $n;
1089 1
        if (is_nan($rF)) {
1090 1
            $rF = 0;
1091
        }
1092 1
        $theta = ($n * ($longitude - $lambdaF)) - (new ArcSecond(29.2985))->asRadians()->getValue();
1093
1094 1
        $easting = $eastingAtFalseOrigin->asMetres()->getValue() + $r * sin($theta);
1095 1
        $northing = $northingAtFalseOrigin->asMetres()->getValue() + $rF - $r * cos($theta);
1096
1097 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1098
    }
1099
1100
    /**
1101
     * Lambert Conic Conformal (2SP Michigan).
1102
     */
1103 1
    public function lambertConicConformal2SPMichigan(
1104
        Projected $to,
1105
        Angle $latitudeOfFalseOrigin,
1106
        Angle $longitudeOfFalseOrigin,
1107
        Angle $latitudeOf1stStandardParallel,
1108
        Angle $latitudeOf2ndStandardParallel,
1109
        Length $eastingAtFalseOrigin,
1110
        Length $northingAtFalseOrigin,
1111
        Scale $ellipsoidScalingFactor
1112
    ): ProjectedPoint {
1113 1
        $latitude = $this->latitude->asRadians()->getValue();
1114 1
        $longitude = $this->longitude->asRadians()->getValue();
1115 1
        $lambdaF = $longitudeOfFalseOrigin->asRadians()->getValue();
1116 1
        $phiF = $latitudeOfFalseOrigin->asRadians()->getValue();
1117 1
        $phi1 = $latitudeOf1stStandardParallel->asRadians()->getValue();
1118 1
        $phi2 = $latitudeOf2ndStandardParallel->asRadians()->getValue();
1119 1
        $K = $ellipsoidScalingFactor->asUnity()->getValue();
1120 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1121 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1122 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1123
1124 1
        $m1 = cos($phi1) / sqrt(1 - $e2 * sin($phi1) ** 2);
1125 1
        $m2 = cos($phi2) / sqrt(1 - $e2 * sin($phi2) ** 2);
1126 1
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1127 1
        $t1 = tan(M_PI / 4 - $phi1 / 2) / ((1 - $e * sin($phi1)) / (1 + $e * sin($phi1))) ** ($e / 2);
1128 1
        $t2 = tan(M_PI / 4 - $phi2 / 2) / ((1 - $e * sin($phi2)) / (1 + $e * sin($phi2))) ** ($e / 2);
1129 1
        $tF = tan(M_PI / 4 - $phiF / 2) / ((1 - $e * sin($phiF)) / (1 + $e * sin($phiF))) ** ($e / 2);
1130 1
        $n = (log($m1) - log($m2)) / (log($t1) - log($t2));
1131 1
        $F = $m1 / ($n * $t1 ** $n);
1132 1
        $r = $a * $K * $F * $t ** $n;
1133 1
        $rF = $a * $K * $F * $tF ** $n;
1134 1
        $theta = $n * ($longitude - $lambdaF);
1135
1136 1
        $easting = $eastingAtFalseOrigin->asMetres()->getValue() + $r * sin($theta);
1137 1
        $northing = $northingAtFalseOrigin->asMetres()->getValue() + $rF - $r * cos($theta);
1138
1139 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1140
    }
1141
1142
    /**
1143
     * Lambert Conic Conformal (2SP).
1144
     */
1145 1
    public function lambertConicConformal2SP(
1146
        Projected $to,
1147
        Angle $latitudeOfFalseOrigin,
1148
        Angle $longitudeOfFalseOrigin,
1149
        Angle $latitudeOf1stStandardParallel,
1150
        Angle $latitudeOf2ndStandardParallel,
1151
        Length $eastingAtFalseOrigin,
1152
        Length $northingAtFalseOrigin
1153
    ): ProjectedPoint {
1154 1
        $latitude = $this->latitude->asRadians()->getValue();
1155 1
        $longitude = $this->longitude->asRadians()->getValue();
1156 1
        $lambdaF = $longitudeOfFalseOrigin->asRadians()->getValue();
1157 1
        $phiF = $latitudeOfFalseOrigin->asRadians()->getValue();
1158 1
        $phi1 = $latitudeOf1stStandardParallel->asRadians()->getValue();
1159 1
        $phi2 = $latitudeOf2ndStandardParallel->asRadians()->getValue();
1160 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1161 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1162 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1163
1164 1
        $m1 = cos($phi1) / sqrt(1 - $e2 * sin($phi1) ** 2);
1165 1
        $m2 = cos($phi2) / sqrt(1 - $e2 * sin($phi2) ** 2);
1166 1
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1167 1
        $t1 = tan(M_PI / 4 - $phi1 / 2) / ((1 - $e * sin($phi1)) / (1 + $e * sin($phi1))) ** ($e / 2);
1168 1
        $t2 = tan(M_PI / 4 - $phi2 / 2) / ((1 - $e * sin($phi2)) / (1 + $e * sin($phi2))) ** ($e / 2);
1169 1
        $tF = tan(M_PI / 4 - $phiF / 2) / ((1 - $e * sin($phiF)) / (1 + $e * sin($phiF))) ** ($e / 2);
1170 1
        $n = (log($m1) - log($m2)) / (log($t1) - log($t2));
1171 1
        $F = $m1 / ($n * $t1 ** $n);
1172 1
        $r = $a * $F * $t ** $n;
1173 1
        $rF = $a * $F * $tF ** $n;
1174 1
        $theta = $n * ($longitude - $lambdaF);
1175
1176 1
        $easting = $eastingAtFalseOrigin->asMetres()->getValue() + $r * sin($theta);
1177 1
        $northing = $northingAtFalseOrigin->asMetres()->getValue() + $rF - $r * cos($theta);
1178
1179 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1180
    }
1181
1182
    /**
1183
     * Lambert Conic Conformal (West Orientated).
1184
     */
1185
    public function lambertConicConformalWestOrientated(
1186
        Projected $to,
1187
        Angle $latitudeOfNaturalOrigin,
1188
        Angle $longitudeOfNaturalOrigin,
1189
        Scale $scaleFactorAtNaturalOrigin,
1190
        Length $falseEasting,
1191
        Length $falseNorthing
1192
    ): ProjectedPoint {
1193
        $latitude = $this->latitude->asRadians()->getValue();
1194
        $longitude = $this->longitude->asRadians()->getValue();
1195
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
1196
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
1197
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
1198
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1199
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1200
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1201
1202
        $mO = cos($latitudeOrigin) / sqrt(1 - $e2 * sin($latitudeOrigin) ** 2);
1203
        $tO = tan(M_PI / 4 - $latitudeOrigin / 2) / ((1 - $e * sin($latitudeOrigin)) / (1 + $e * sin($latitudeOrigin))) ** ($e / 2);
1204
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1205
        $n = sin($latitudeOrigin);
1206
        $F = $mO / ($n * $tO ** $n);
1207
        $rO = $a * $F * $tO ** $n ** $kO;
1208
        $r = $a * $F * $t ** $n ** $kO;
1209
        $theta = $n * ($longitude - $longitudeOrigin);
1210
1211
        $westing = $falseEasting->asMetres()->getValue() - $r * sin($theta);
1212
        $northing = $falseNorthing->asMetres()->getValue() + $rO - $r * cos($theta);
1213
1214
        return ProjectedPoint::create(new Metre(-$westing), new Metre($northing), new Metre($westing), new Metre(-$northing), $to, $this->epoch);
1215
    }
1216
1217
    /**
1218
     * Lambert Conic Near-Conformal
1219
     * The Lambert Near-Conformal projection is derived from the Lambert Conformal Conic projection by truncating the
1220
     * series expansion of the projection formulae.
1221
     */
1222 1
    public function lambertConicNearConformal(
1223
        Projected $to,
1224
        Angle $latitudeOfNaturalOrigin,
1225
        Angle $longitudeOfNaturalOrigin,
1226
        Scale $scaleFactorAtNaturalOrigin,
1227
        Length $falseEasting,
1228
        Length $falseNorthing
1229
    ): ProjectedPoint {
1230 1
        $latitude = $this->latitude->asRadians()->getValue();
1231 1
        $longitude = $this->longitude->asRadians()->getValue();
1232 1
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
1233 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
1234 1
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
1235 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1236 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1237 1
        $f = $this->crs->getDatum()->getEllipsoid()->getInverseFlattening();
1238
1239 1
        $n = $f / (2 - $f);
1240 1
        $rhoO = $a * (1 - $e2) / (1 - $e2 * sin($latitudeOrigin) ** 2) ** (3 / 2);
1241 1
        $nuO = $a / sqrt(1 - $e2 * (sin($latitudeOrigin) ** 2));
1242 1
        $A = 1 / (6 * $rhoO * $nuO);
1243 1
        $APrime = $a * (1 - $n + 5 * ($n ** 2 - $n ** 3) / 4 + 81 * ($n ** 4 - $n ** 5) / 64);
1244 1
        $BPrime = 3 * $a * ($n - $n ** 2 + 7 * ($n ** 3 - $n ** 4) / 8 + 55 * $n ** 5 / 64) / 2;
1245 1
        $CPrime = 15 * $a * ($n ** 2 - $n ** 3 + 3 * ($n ** 4 - $n ** 5) / 4) / 16;
1246 1
        $DPrime = 35 * $a * ($n ** 3 - $n ** 4 + 11 * $n ** 5 / 16) / 48;
1247 1
        $EPrime = 315 * $a * ($n ** 4 - $n ** 5) / 512;
1248 1
        $rO = $kO * $nuO / tan($latitudeOrigin);
1249 1
        $sO = $APrime * $latitudeOrigin - $BPrime * sin(2 * $latitudeOrigin) + $CPrime * sin(4 * $latitudeOrigin) - $DPrime * sin(6 * $latitudeOrigin) + $EPrime * sin(8 * $latitudeOrigin);
1250 1
        $s = $APrime * $latitude - $BPrime * sin(2 * $latitude) + $CPrime * sin(4 * $latitude) - $DPrime * sin(6 * $latitude) + $EPrime * sin(8 * $latitude);
1251 1
        $m = $s - $sO;
1252 1
        $M = $kO * ($m + $A * $m ** 3);
1253 1
        $r = $rO - $M;
1254 1
        $theta = ($longitude - $longitudeOrigin) * sin($latitudeOrigin);
1255
1256 1
        $easting = $falseEasting->asMetres()->getValue() + $r * sin($theta);
1257 1
        $northing = $falseNorthing->asMetres()->getValue() + $M + $r * sin($theta) * tan($theta / 2);
1258
1259 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1260
    }
1261
1262
    /**
1263
     * Lambert Cylindrical Equal Area
1264
     * This is the ellipsoidal form of the projection.
1265
     */
1266 1
    public function lambertCylindricalEqualArea(
1267
        Projected $to,
1268
        Angle $latitudeOf1stStandardParallel,
1269
        Angle $longitudeOfNaturalOrigin,
1270
        Length $falseEasting,
1271
        Length $falseNorthing
1272
    ): ProjectedPoint {
1273 1
        $latitude = $this->latitude->asRadians()->getValue();
1274 1
        $longitude = $this->longitude->asRadians()->getValue();
1275 1
        $latitudeFirstParallel = $latitudeOf1stStandardParallel->asRadians()->getValue();
1276 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
1277 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1278 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1279 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1280
1281 1
        $k = cos($latitudeFirstParallel) / sqrt(1 - $e2 * sin($latitudeFirstParallel) ** 2);
1282 1
        $q = (1 - $e2) * ((sin($latitude) / (1 - $e2 * sin($latitude) ** 2)) - (1 / (2 * $e)) * log((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))));
1283
1284 1
        $x = $a * $k * ($longitude - $longitudeOrigin);
1285 1
        $y = $a * $q / (2 * $k);
1286
1287 1
        $easting = $falseEasting->asMetres()->getValue() + $x;
1288 1
        $northing = $falseNorthing->asMetres()->getValue() + $y;
1289
1290 1
        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 1
    public function modifiedAzimuthalEquidistant(
1299
        Projected $to,
1300
        Angle $latitudeOfNaturalOrigin,
1301
        Angle $longitudeOfNaturalOrigin,
1302
        Length $falseEasting,
1303
        Length $falseNorthing
1304
    ): ProjectedPoint {
1305 1
        $latitude = $this->latitude->asRadians()->getValue();
1306 1
        $longitude = $this->longitude->asRadians()->getValue();
1307 1
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
1308 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
1309 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1310 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1311 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1312
1313 1
        $nuO = $a / sqrt(1 - $e2 * sin($latitudeOrigin) ** 2);
1314 1
        $nu = $a / sqrt(1 - $e2 * sin($latitude) ** 2);
1315 1
        $psi = atan((1 - $e2) * tan($latitude) + ($e2 * $nuO * sin($latitudeOrigin)) / ($nu * cos($latitude)));
1316 1
        $alpha = atan2(sin($longitude - $longitudeOrigin), (cos($latitudeOrigin) * tan($psi) - sin($latitudeOrigin) * cos($longitude - $longitudeOrigin)));
1317 1
        $G = $e * sin($latitudeOrigin) / sqrt(1 - $e2);
1318 1
        $H = $e * cos($latitudeOrigin) * cos($alpha) / sqrt(1 - $e2);
1319
1320 1
        if (sin($alpha) === 0.0) {
1321
            $s = self::asin(cos($latitudeOrigin) * sin($psi) - sin($latitudeOrigin) * cos($alpha)) * cos($alpha) / abs(cos($alpha));
1322
        } else {
1323 1
            $s = self::asin(sin($longitude - $longitudeOrigin) * cos($psi) / sin($alpha));
1324
        }
1325
1326 1
        $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));
1327
1328 1
        $easting = $falseEasting->asMetres()->getValue() + $c * sin($alpha);
1329 1
        $northing = $falseNorthing->asMetres()->getValue() + $c * cos($alpha);
1330
1331 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1332
    }
1333
1334
    /**
1335
     * Oblique Stereographic
1336
     * This is not the same as the projection method of the same name in USGS Professional Paper no. 1395, "Map
1337
     * Projections - A Working Manual" by John P. Snyder.
1338
     */
1339 1
    public function obliqueStereographic(
1340
        Projected $to,
1341
        Angle $latitudeOfNaturalOrigin,
1342
        Angle $longitudeOfNaturalOrigin,
1343
        Scale $scaleFactorAtNaturalOrigin,
1344
        Length $falseEasting,
1345
        Length $falseNorthing
1346
    ): ProjectedPoint {
1347 1
        $latitude = $this->latitude->asRadians()->getValue();
1348 1
        $longitude = $this->longitude->asRadians()->getValue();
1349 1
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
1350 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
1351 1
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
1352 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1353 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1354 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1355
1356 1
        $rhoOrigin = $a * (1 - $e2) / (1 - $e2 * sin($latitudeOrigin) ** 2) ** (3 / 2);
1357 1
        $nuOrigin = $a / sqrt(1 - $e2 * (sin($latitudeOrigin) ** 2));
1358 1
        $R = sqrt($rhoOrigin * $nuOrigin);
1359
1360 1
        $n = sqrt(1 + ($e2 * cos($latitudeOrigin) ** 4 / (1 - $e2)));
1361 1
        $S1 = (1 + sin($latitudeOrigin)) / (1 - sin($latitudeOrigin));
1362 1
        $S2 = (1 - $e * sin($latitudeOrigin)) / (1 + $e * sin($latitudeOrigin));
1363 1
        $w1 = ($S1 * ($S2 ** $e)) ** $n;
1364 1
        $c = (($n + sin($latitudeOrigin)) * (1 - ($w1 - 1) / ($w1 + 1))) / (($n - sin($latitudeOrigin)) * (1 + ($w1 - 1) / ($w1 + 1)));
1365 1
        $w2 = $c * $w1;
1366 1
        $chiOrigin = self::asin(($w2 - 1) / ($w2 + 1));
1367
1368 1
        $lambda = $n * ($longitude - $longitudeOrigin) + $longitudeOrigin;
1369
1370 1
        $Sa = (1 + sin($latitude)) / (1 - sin($latitude));
1371 1
        $Sb = (1 - $e * sin($latitude)) / (1 + $e * sin($latitude));
1372 1
        $w = $c * ($Sa * ($Sb ** $e)) ** $n;
1373 1
        $chi = self::asin(($w - 1) / ($w + 1));
1374
1375 1
        $B = (1 + sin($chi) * sin($chiOrigin) + cos($chi) * cos($chiOrigin) * cos($lambda - $longitudeOrigin));
1376
1377 1
        $easting = $falseEasting->asMetres()->getValue() + 2 * $R * $kO * cos($chi) * sin($lambda - $longitudeOrigin) / $B;
1378 1
        $northing = $falseNorthing->asMetres()->getValue() + 2 * $R * $kO * (sin($chi) * cos($chiOrigin) - cos($chi) * sin($chiOrigin) * cos($lambda - $longitudeOrigin)) / $B;
1379
1380 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1381
    }
1382
1383
    /**
1384
     * Polar Stereographic (variant A)
1385
     * Latitude of natural origin must be either 90 degrees or -90 degrees (or equivalent in alternative angle unit).
1386
     */
1387 1
    public function polarStereographicVariantA(
1388
        Projected $to,
1389
        Angle $latitudeOfNaturalOrigin,
1390
        Angle $longitudeOfNaturalOrigin,
1391
        Scale $scaleFactorAtNaturalOrigin,
1392
        Length $falseEasting,
1393
        Length $falseNorthing
1394
    ): ProjectedPoint {
1395 1
        $latitude = $this->latitude->asRadians()->getValue();
1396 1
        $longitude = $this->longitude->asRadians()->getValue();
1397 1
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
1398 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
1399 1
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
1400 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1401 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1402
1403 1
        if ($latitudeOrigin < 0) {
1404
            $t = tan(M_PI / 4 + $latitude / 2) / (((1 + $e * sin($latitude)) / (1 - $e * sin($latitude))) ** ($e / 2));
1405
        } else {
1406 1
            $t = tan(M_PI / 4 - $latitude / 2) * (((1 + $e * sin($latitude)) / (1 - $e * sin($latitude))) ** ($e / 2));
1407
        }
1408 1
        $rho = 2 * $a * $kO * $t / sqrt((1 + $e) ** (1 + $e) * (1 - $e) ** (1 - $e));
1409
1410 1
        $theta = $longitude - $longitudeOrigin;
1411 1
        $dE = $rho * sin($theta);
1412 1
        $dN = $rho * cos($theta);
1413
1414 1
        $easting = $falseEasting->asMetres()->getValue() + $dE;
1415 1
        if ($latitudeOrigin < 0) {
1416
            $northing = $falseNorthing->asMetres()->getValue() + $dN;
1417
        } else {
1418 1
            $northing = $falseNorthing->asMetres()->getValue() - $dN;
1419
        }
1420
1421 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1422
    }
1423
1424
    /**
1425
     * Polar Stereographic (variant B).
1426
     */
1427 1
    public function polarStereographicVariantB(
1428
        Projected $to,
1429
        Angle $latitudeOfStandardParallel,
1430
        Angle $longitudeOfOrigin,
1431
        Length $falseEasting,
1432
        Length $falseNorthing
1433
    ): ProjectedPoint {
1434 1
        $latitude = $this->latitude->asRadians()->getValue();
1435 1
        $longitude = $this->longitude->asRadians()->getValue();
1436 1
        $firstStandardParallel = $latitudeOfStandardParallel->asRadians()->getValue();
1437 1
        $longitudeOrigin = $longitudeOfOrigin->asRadians()->getValue();
1438 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1439 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1440 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1441
1442 1
        if ($firstStandardParallel < 0) {
1443 1
            $tF = tan(M_PI / 4 + $firstStandardParallel / 2) / (((1 + $e * sin($firstStandardParallel)) / (1 - $e * sin($firstStandardParallel))) ** ($e / 2));
1444 1
            $t = tan(M_PI / 4 + $latitude / 2) / (((1 + $e * sin($latitude)) / (1 - $e * sin($latitude))) ** ($e / 2));
1445
        } else {
1446
            $tF = tan(M_PI / 4 - $firstStandardParallel / 2) * (((1 + $e * sin($firstStandardParallel)) / (1 - $e * sin($firstStandardParallel))) ** ($e / 2));
1447
            $t = tan(M_PI / 4 - $latitude / 2) * (((1 + $e * sin($latitude)) / (1 - $e * sin($latitude))) ** ($e / 2));
1448
        }
1449 1
        $mF = cos($firstStandardParallel) / sqrt(1 - $e2 * sin($firstStandardParallel) ** 2);
1450 1
        $kO = $mF * sqrt((1 + $e) ** (1 + $e) * (1 - $e) ** (1 - $e)) / (2 * $tF);
1451
1452 1
        $rho = 2 * $a * $kO * $t / sqrt((1 + $e) ** (1 + $e) * (1 - $e) ** (1 - $e));
1453
1454 1
        $theta = $longitude - $longitudeOrigin;
1455 1
        $dE = $rho * sin($theta);
1456 1
        $dN = $rho * cos($theta);
1457
1458 1
        $easting = $falseEasting->asMetres()->getValue() + $dE;
1459 1
        if ($firstStandardParallel < 0) {
1460 1
            $northing = $falseNorthing->asMetres()->getValue() + $dN;
1461
        } else {
1462
            $northing = $falseNorthing->asMetres()->getValue() - $dN;
1463
        }
1464
1465 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1466
    }
1467
1468
    /**
1469
     * Polar Stereographic (variant C).
1470
     */
1471 1
    public function polarStereographicVariantC(
1472
        Projected $to,
1473
        Angle $latitudeOfStandardParallel,
1474
        Angle $longitudeOfOrigin,
1475
        Length $eastingAtFalseOrigin,
1476
        Length $northingAtFalseOrigin
1477
    ): ProjectedPoint {
1478 1
        $latitude = $this->latitude->asRadians()->getValue();
1479 1
        $longitude = $this->longitude->asRadians()->getValue();
1480 1
        $firstStandardParallel = $latitudeOfStandardParallel->asRadians()->getValue();
1481 1
        $longitudeOrigin = $longitudeOfOrigin->asRadians()->getValue();
1482 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1483 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1484 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1485
1486 1
        if ($firstStandardParallel < 0) {
1487 1
            $tF = tan(M_PI / 4 + $firstStandardParallel / 2) / (((1 + $e * sin($firstStandardParallel)) / (1 - $e * sin($firstStandardParallel))) ** ($e / 2));
1488 1
            $t = tan(M_PI / 4 + $latitude / 2) / (((1 + $e * sin($latitude)) / (1 - $e * sin($latitude))) ** ($e / 2));
1489
        } else {
1490
            $tF = tan(M_PI / 4 - $firstStandardParallel / 2) * (((1 + $e * sin($firstStandardParallel)) / (1 - $e * sin($firstStandardParallel))) ** ($e / 2));
1491
            $t = tan(M_PI / 4 - $latitude / 2) * (((1 + $e * sin($latitude)) / (1 - $e * sin($latitude))) ** ($e / 2));
1492
        }
1493 1
        $mF = cos($firstStandardParallel) / sqrt(1 - $e2 * sin($firstStandardParallel) ** 2);
1494
1495 1
        $rhoF = $a * $mF;
1496 1
        $rho = $rhoF * $t / $tF;
1497
1498 1
        $theta = $longitude - $longitudeOrigin;
1499 1
        $dE = $rho * sin($theta);
1500 1
        $dN = $rho * cos($theta);
1501
1502 1
        $easting = $eastingAtFalseOrigin->asMetres()->getValue() + $dE;
1503 1
        if ($firstStandardParallel < 0) {
1504 1
            $northing = $northingAtFalseOrigin->asMetres()->getValue() - $rhoF + $dN;
1505
        } else {
1506
            $northing = $northingAtFalseOrigin->asMetres()->getValue() + $rhoF - $dN;
1507
        }
1508
1509 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1510
    }
1511
1512
    /**
1513
     * Popular Visualisation Pseudo Mercator
1514
     * Applies spherical formulas to the ellipsoid. As such does not have the properties of a true Mercator projection.
1515
     */
1516 1
    public function popularVisualisationPseudoMercator(
1517
        Projected $to,
1518
        Angle $latitudeOfNaturalOrigin,
1519
        Angle $longitudeOfNaturalOrigin,
1520
        Length $falseEasting,
1521
        Length $falseNorthing
1522
    ): ProjectedPoint {
1523 1
        $latitude = $this->latitude->asRadians()->getValue();
1524 1
        $longitude = $this->longitude->asRadians()->getValue();
1525 1
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
0 ignored issues
show
Unused Code introduced by
The assignment to $latitudeOrigin is dead and can be removed.
Loading history...
1526 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
1527 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1528
1529 1
        $easting = $falseEasting->asMetres()->getValue() + $a * ($longitude - $longitudeOrigin);
1530 1
        $northing = $falseNorthing->asMetres()->getValue() + $a * log(tan(M_PI / 4 + $latitude / 2));
1531
1532 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1533
    }
1534
1535
    /**
1536
     * Mercator (variant A)
1537
     * Note that in these formulas the parameter latitude of natural origin (latO) is not used. However for this
1538
     * Mercator (variant A) method the EPSG dataset includes this parameter, which must have a value of zero, for
1539
     * completeness in CRS labelling.
1540
     */
1541 1
    public function mercatorVariantA(
1542
        Projected $to,
1543
        Angle $latitudeOfNaturalOrigin,
1544
        Angle $longitudeOfNaturalOrigin,
1545
        Scale $scaleFactorAtNaturalOrigin,
1546
        Length $falseEasting,
1547
        Length $falseNorthing
1548
    ): ProjectedPoint {
1549 1
        $latitude = $this->latitude->asRadians()->getValue();
1550 1
        $longitude = $this->longitude->asRadians()->getValue();
1551
1552 1
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
0 ignored issues
show
Unused Code introduced by
The assignment to $latitudeOrigin is dead and can be removed.
Loading history...
1553 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
1554 1
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
1555
1556 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1557 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1558
1559 1
        $easting = $falseEasting->asMetres()->getValue() + $a * $kO * ($longitude - $longitudeOrigin);
1560 1
        $northing = $falseNorthing->asMetres()->getValue() + $a * $kO * log(tan(M_PI / 4 + $latitude / 2) * ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2));
1561
1562 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1563
    }
1564
1565
    /**
1566
     * Mercator (variant B)
1567
     * Used for most nautical charts.
1568
     */
1569 1
    public function mercatorVariantB(
1570
        Projected $to,
1571
        Angle $latitudeOf1stStandardParallel,
1572
        Angle $longitudeOfNaturalOrigin,
1573
        Length $falseEasting,
1574
        Length $falseNorthing
1575
    ): ProjectedPoint {
1576 1
        $latitude = $this->latitude->asRadians()->getValue();
1577 1
        $longitude = $this->longitude->asRadians()->getValue();
1578 1
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
1579 1
        $firstStandardParallel = $latitudeOf1stStandardParallel->asRadians()->getValue();
1580 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1581 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1582 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1583
1584 1
        $kO = cos($firstStandardParallel) / sqrt(1 - $e2 * sin($firstStandardParallel) ** 2);
1585
1586 1
        $easting = $falseEasting->asMetres()->getValue() + $a * $kO * ($longitude - $longitudeOrigin);
1587 1
        $northing = $falseNorthing->asMetres()->getValue() + $a * $kO * log(tan(M_PI / 4 + $latitude / 2) * ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2));
1588
1589 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1590
    }
1591
1592
    /**
1593
     * Longitude rotation
1594
     * This transformation allows calculation of the longitude of a point in the target system by adding the parameter
1595
     * value to the longitude value of the point in the source system.
1596
     */
1597 1
    public function longitudeRotation(
1598
        Geographic $to,
1599
        Angle $longitudeOffset
1600
    ): self {
1601 1
        $newLongitude = $this->longitude->add($longitudeOffset);
1602 1
        if ($newLongitude->asDegrees()->getValue() < -180) {
1603
            $newLongitude = $newLongitude->add(new Degree(360));
1604
        }
1605
1606 1
        return static::create($this->latitude, $newLongitude, $this->height, $to, $this->epoch);
1607
    }
1608
1609
    /**
1610
     * Hotine Oblique Mercator (variant A).
1611
     */
1612 1
    public function obliqueMercatorHotineVariantA(
1613
        Projected $to,
1614
        Angle $latitudeOfProjectionCentre,
1615
        Angle $longitudeOfProjectionCentre,
1616
        Angle $azimuthOfInitialLine,
1617
        Angle $angleFromRectifiedToSkewGrid,
1618
        Scale $scaleFactorOnInitialLine,
1619
        Length $falseEasting,
1620
        Length $falseNorthing
1621
    ): ProjectedPoint {
1622 1
        $latitude = $this->latitude->asRadians()->getValue();
1623 1
        $longitude = $this->longitude->asRadians()->getValue();
1624 1
        $latC = $latitudeOfProjectionCentre->asRadians()->getValue();
1625 1
        $lonC = $longitudeOfProjectionCentre->asRadians()->getValue();
1626 1
        $alphaC = $azimuthOfInitialLine->asRadians()->getValue();
1627 1
        $kC = $scaleFactorOnInitialLine->asUnity()->getValue();
1628 1
        $gammaC = $angleFromRectifiedToSkewGrid->asRadians()->getValue();
1629 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1630 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1631 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1632
1633 1
        $B = sqrt(1 + ($e2 * cos($latC) ** 4 / (1 - $e2)));
1634 1
        $A = $a * $B * $kC * sqrt(1 - $e2) / (1 - $e2 * sin($latC) ** 2);
1635 1
        $tO = tan(M_PI / 4 - $latC / 2) / ((1 - $e * sin($latC)) / (1 + $e * sin($latC))) ** ($e / 2);
1636 1
        $D = $B * sqrt((1 - $e2)) / (cos($latC) * sqrt(1 - $e2 * sin($latC) ** 2));
1637 1
        $DD = max(1, $D ** 2);
1638 1
        $F = $D + sqrt($DD - 1) * static::sign($latC);
1639 1
        $H = $F * ($tO) ** $B;
1640 1
        $G = ($F - 1 / $F) / 2;
1641 1
        $gammaO = self::asin(sin($alphaC) / $D);
1642 1
        $lonO = $lonC - (self::asin($G * tan($gammaO))) / $B;
1643
1644 1
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1645 1
        $Q = $H / $t ** $B;
1646 1
        $S = ($Q - 1 / $Q) / 2;
1647 1
        $T = ($Q + 1 / $Q) / 2;
1648 1
        $V = sin($B * ($longitude - $lonO));
1649 1
        $U = (-$V * cos($gammaO) + $S * sin($gammaO)) / $T;
1650 1
        $v = $A * log((1 - $U) / (1 + $U)) / (2 * $B);
1651 1
        $u = $A * atan2(($S * cos($gammaO) + $V * sin($gammaO)), cos($B * ($longitude - $lonO))) / $B;
1652
1653 1
        $easting = $v * cos($gammaC) + $u * sin($gammaC) + $falseEasting->asMetres()->getValue();
1654 1
        $northing = $u * cos($gammaC) - $v * sin($gammaC) + $falseNorthing->asMetres()->getValue();
1655
1656 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1657
    }
1658
1659
    /**
1660
     * Hotine Oblique Mercator (variant B).
1661
     */
1662 1
    public function obliqueMercatorHotineVariantB(
1663
        Projected $to,
1664
        Angle $latitudeOfProjectionCentre,
1665
        Angle $longitudeOfProjectionCentre,
1666
        Angle $azimuthOfInitialLine,
1667
        Angle $angleFromRectifiedToSkewGrid,
1668
        Scale $scaleFactorOnInitialLine,
1669
        Length $eastingAtProjectionCentre,
1670
        Length $northingAtProjectionCentre
1671
    ): ProjectedPoint {
1672 1
        $latitude = $this->latitude->asRadians()->getValue();
1673 1
        $longitude = $this->longitude->asRadians()->getValue();
1674 1
        $latC = $latitudeOfProjectionCentre->asRadians()->getValue();
1675 1
        $lonC = $longitudeOfProjectionCentre->asRadians()->getValue();
1676 1
        $alphaC = $azimuthOfInitialLine->asRadians()->getValue();
1677 1
        $kC = $scaleFactorOnInitialLine->asUnity()->getValue();
1678 1
        $gammaC = $angleFromRectifiedToSkewGrid->asRadians()->getValue();
1679 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1680 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1681 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1682
1683 1
        $B = sqrt(1 + ($e2 * cos($latC) ** 4 / (1 - $e2)));
1684 1
        $A = $a * $B * $kC * sqrt(1 - $e2) / (1 - $e2 * sin($latC) ** 2);
1685 1
        $tO = tan(M_PI / 4 - $latC / 2) / ((1 - $e * sin($latC)) / (1 + $e * sin($latC))) ** ($e / 2);
1686 1
        $D = $B * sqrt((1 - $e2)) / (cos($latC) * sqrt(1 - $e2 * sin($latC) ** 2));
1687 1
        $DD = max(1, $D ** 2);
1688 1
        $F = $D + sqrt($DD - 1) * static::sign($latC);
1689 1
        $H = $F * ($tO) ** $B;
1690 1
        $G = ($F - 1 / $F) / 2;
1691 1
        $gammaO = self::asin(sin($alphaC) / $D);
1692 1
        $lonO = $lonC - (self::asin($G * tan($gammaO))) / $B;
1693 1
        $vC = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $vC is dead and can be removed.
Loading history...
1694 1
        if ($alphaC === M_PI / 2) {
1695
            $uC = $A * ($lonC - $lonO);
1696
        } else {
1697 1
            $uC = ($A / $B) * atan2(sqrt($DD - 1), cos($alphaC)) * static::sign($latC);
1698
        }
1699
1700 1
        $t = tan(M_PI / 4 - $latitude / 2) / ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2);
1701 1
        $Q = $H / $t ** $B;
1702 1
        $S = ($Q - 1 / $Q) / 2;
1703 1
        $T = ($Q + 1 / $Q) / 2;
1704 1
        $V = sin($B * ($longitude - $lonO));
1705 1
        $U = (-$V * cos($gammaO) + $S * sin($gammaO)) / $T;
1706 1
        $v = $A * log((1 - $U) / (1 + $U)) / (2 * $B);
1707
1708 1
        if ($alphaC === M_PI / 2) {
1709
            if ($longitude === $lonC) {
1710
                $u = 0;
1711
            } else {
1712
                $u = ($A * atan(($S * cos($gammaO) + $V * sin($gammaO)) / cos($B * ($longitude - $lonO))) / $B) - (abs($uC) * static::sign($latC) * static::sign($lonC - $longitude));
1713
            }
1714
        } else {
1715 1
            $u = ($A * atan2(($S * cos($gammaO) + $V * sin($gammaO)), cos($B * ($longitude - $lonO))) / $B) - (abs($uC) * static::sign($latC));
1716
        }
1717
1718 1
        $easting = $v * cos($gammaC) + $u * sin($gammaC) + $eastingAtProjectionCentre->asMetres()->getValue();
1719 1
        $northing = $u * cos($gammaC) - $v * sin($gammaC) + $northingAtProjectionCentre->asMetres()->getValue();
1720
1721 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1722
    }
1723
1724
    /**
1725
     * Laborde Oblique Mercator.
1726
     */
1727 1
    public function obliqueMercatorLaborde(
1728
        Projected $to,
1729
        Angle $latitudeOfProjectionCentre,
1730
        Angle $longitudeOfProjectionCentre,
1731
        Angle $azimuthOfInitialLine,
1732
        Scale $scaleFactorOnInitialLine,
1733
        Length $falseEasting,
1734
        Length $falseNorthing
1735
    ): ProjectedPoint {
1736 1
        $latitude = $this->latitude->asRadians()->getValue();
1737 1
        $longitude = $this->longitude->asRadians()->getValue();
1738 1
        $latC = $latitudeOfProjectionCentre->asRadians()->getValue();
1739 1
        $lonC = $longitudeOfProjectionCentre->asRadians()->getValue();
1740 1
        $alphaC = $azimuthOfInitialLine->asRadians()->getValue();
1741 1
        $kC = $scaleFactorOnInitialLine->asUnity()->getValue();
1742 1
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1743 1
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1744 1
        $e2 = $this->crs->getDatum()->getEllipsoid()->getEccentricitySquared();
1745
1746 1
        $B = sqrt(1 + ($e2 * cos($latC) ** 4 / (1 - $e2)));
1747 1
        $latS = self::asin(sin($latC) / $B);
1748 1
        $R = $a * $kC * (sqrt(1 - $e2) / (1 - $e2 * sin($latC) ** 2));
1749 1
        $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));
1750
1751 1
        $L = $B * ($longitude - $lonC);
1752 1
        $q = $C + $B * log(tan(M_PI / 4 + $latitude / 2) * ((1 - $e * sin($latitude)) / (1 + $e * sin($latitude))) ** ($e / 2));
1753 1
        $P = 2 * atan(M_E ** $q) - M_PI / 2;
1754 1
        $U = cos($P) * cos($L) * cos($latS) + sin($P) * sin($latS);
1755 1
        $V = cos($P) * cos($L) * sin($latS) - sin($P) * cos($latS);
1756 1
        $W = cos($P) * sin($L);
1757 1
        $d = sqrt($U ** 2 + $V ** 2);
1758 1
        if ($d === 0.0) {
1759
            $LPrime = 0;
1760
            $PPrime = static::sign($W) * M_PI / 2;
1761
        } else {
1762 1
            $LPrime = 2 * atan($V / ($U + $d));
1763 1
            $PPrime = atan($W / $d);
1764
        }
1765 1
        $H = new ComplexNumber(-$LPrime, log(tan(M_PI / 4 + $PPrime / 2)));
1766 1
        $G = (new ComplexNumber(1 - cos(2 * $alphaC), sin(2 * $alphaC)))->divide(new ComplexNumber(12, 0));
1767
1768 1
        $easting = $falseEasting->asMetres()->getValue() + $R * $H->pow(3)->multiply($G)->add($H)->getImaginary();
1769 1
        $northing = $falseNorthing->asMetres()->getValue() + $R * $H->pow(3)->multiply($G)->add($H)->getReal();
1770
1771 1
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1772
    }
1773
1774
    /**
1775
     * Transverse Mercator.
1776
     */
1777 7
    public function transverseMercator(
1778
        Projected $to,
1779
        Angle $latitudeOfNaturalOrigin,
1780
        Angle $longitudeOfNaturalOrigin,
1781
        Scale $scaleFactorAtNaturalOrigin,
1782
        Length $falseEasting,
1783
        Length $falseNorthing
1784
    ): ProjectedPoint {
1785 7
        $latitude = $this->latitude->asRadians()->getValue();
1786 7
        $longitude = $this->longitude->asRadians()->getValue();
1787 7
        $latitudeOrigin = $latitudeOfNaturalOrigin->asRadians()->getValue();
1788 7
        $longitudeOrigin = $longitudeOfNaturalOrigin->asRadians()->getValue();
1789 7
        $kO = $scaleFactorAtNaturalOrigin->asUnity()->getValue();
1790 7
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1791 7
        $e = $this->crs->getDatum()->getEllipsoid()->getEccentricity();
1792 7
        $f = $this->crs->getDatum()->getEllipsoid()->getInverseFlattening();
1793
1794 7
        $n = $f / (2 - $f);
1795 7
        $B = ($a / (1 + $n)) * (1 + $n ** 2 / 4 + $n ** 4 / 64);
1796
1797 7
        $h1 = $n / 2 - (2 / 3) * $n ** 2 + (5 / 16) * $n ** 3 + (41 / 180) * $n ** 4;
1798 7
        $h2 = (13 / 48) * $n ** 2 - (3 / 5) * $n ** 3 + (557 / 1440) * $n ** 4;
1799 7
        $h3 = (61 / 240) * $n ** 3 - (103 / 140) * $n ** 4;
1800 7
        $h4 = (49561 / 161280) * $n ** 4;
1801
1802 7
        if ($latitudeOrigin === 0.0) {
0 ignored issues
show
introduced by
The condition $latitudeOrigin === 0.0 is always false.
Loading history...
1803 5
            $mO = 0;
1804 2
        } elseif ($latitudeOrigin === M_PI / 2) {
1805
            $mO = $B * M_PI / 2;
1806 2
        } elseif ($latitudeOrigin === -M_PI / 2) {
1807
            $mO = $B * -M_PI / 2;
1808
        } else {
1809 2
            $qO = asinh(tan($latitudeOrigin)) - ($e * atanh($e * sin($latitudeOrigin)));
1810 2
            $betaO = atan(sinh($qO));
1811 2
            $xiO0 = self::asin(sin($betaO));
1812 2
            $xiO1 = $h1 * sin(2 * $xiO0);
1813 2
            $xiO2 = $h2 * sin(4 * $xiO0);
1814 2
            $xiO3 = $h3 * sin(6 * $xiO0);
1815 2
            $xiO4 = $h4 * sin(8 * $xiO0);
1816 2
            $xiO = $xiO0 + $xiO1 + $xiO2 + $xiO3 + $xiO4;
1817 2
            $mO = $B * $xiO;
1818
        }
1819
1820 7
        $Q = asinh(tan($latitude)) - ($e * atanh($e * sin($latitude)));
1821 7
        $beta = atan(sinh($Q));
1822 7
        $eta0 = atanh(cos($beta) * sin($longitude - $longitudeOrigin));
1823 7
        $xi0 = self::asin(sin($beta) * cosh($eta0));
1824 7
        $xi1 = $h1 * sin(2 * $xi0) * cosh(2 * $eta0);
1825 7
        $eta1 = $h1 * cos(2 * $xi0) * sinh(2 * $eta0);
1826 7
        $xi2 = $h2 * sin(4 * $xi0) * cosh(4 * $eta0);
1827 7
        $eta2 = $h2 * cos(4 * $xi0) * sinh(4 * $eta0);
1828 7
        $xi3 = $h3 * sin(6 * $xi0) * cosh(6 * $eta0);
1829 7
        $eta3 = $h3 * cos(6 * $xi0) * sinh(6 * $eta0);
1830 7
        $xi4 = $h4 * sin(8 * $xi0) * cosh(8 * $eta0);
1831 7
        $eta4 = $h4 * cos(8 * $xi0) * sinh(8 * $eta0);
1832 7
        $xi = $xi0 + $xi1 + $xi2 + $xi3 + $xi4;
1833 7
        $eta = $eta0 + $eta1 + $eta2 + $eta3 + $eta4;
1834
1835 7
        $easting = $falseEasting->asMetres()->getValue() + $kO * $B * $eta;
1836 7
        $northing = $falseNorthing->asMetres()->getValue() + $kO * ($B * $xi - $mO);
1837
1838 7
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1839
    }
1840
1841
    /**
1842
     * Transverse Mercator Zoned Grid System
1843
     * If locations fall outwith the fixed zones the general Transverse Mercator method (code 9807) must be used for
1844
     * each zone.
1845
     */
1846 3
    public function transverseMercatorZonedGrid(
1847
        Projected $to,
1848
        Angle $latitudeOfNaturalOrigin,
1849
        Angle $initialLongitude,
1850
        Angle $zoneWidth,
1851
        Scale $scaleFactorAtNaturalOrigin,
1852
        Length $falseEasting,
1853
        Length $falseNorthing
1854
    ): ProjectedPoint {
1855 3
        $W = $zoneWidth->asDegrees()->getValue();
1856 3
        $Z = ($this->longitude->subtract($initialLongitude)->asDegrees()->getValue() / $W) % (360 / $W) + 1;
1857
1858 3
        $longitudeOrigin = $initialLongitude->add(new Degree($Z * $W - $W / 2));
1859 3
        $falseEasting = $falseEasting->add(new Metre($Z * 1000000));
1860
1861 3
        return $this->transverseMercator($to, $latitudeOfNaturalOrigin, $longitudeOrigin, $scaleFactorAtNaturalOrigin, $falseEasting, $falseNorthing);
1862
    }
1863
1864
    /**
1865
     * New Zealand Map Grid.
1866
     */
1867 3
    public function newZealandMapGrid(
1868
        Projected $to,
1869
        Angle $latitudeOfNaturalOrigin,
1870
        Angle $longitudeOfNaturalOrigin,
1871
        Length $falseEasting,
1872
        Length $falseNorthing
1873
    ): ProjectedPoint {
1874 3
        $a = $this->crs->getDatum()->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue();
1875
1876 3
        $deltaLatitudeToOrigin = Angle::convert($this->latitude->subtract($latitudeOfNaturalOrigin), Angle::EPSG_ARC_SECOND)->getValue();
1877 3
        $deltaLongitudeToOrigin = $this->longitude->subtract($longitudeOfNaturalOrigin)->asRadians();
1878
1879 3
        $deltaPsi = 0;
1880 3
        $deltaPsi += 0.6399175073 * ($deltaLatitudeToOrigin * 0.00001) ** 1;
1881 3
        $deltaPsi += -0.1358797613 * ($deltaLatitudeToOrigin * 0.00001) ** 2;
1882 3
        $deltaPsi += 0.063294409 * ($deltaLatitudeToOrigin * 0.00001) ** 3;
1883 3
        $deltaPsi += -0.02526853 * ($deltaLatitudeToOrigin * 0.00001) ** 4;
1884 3
        $deltaPsi += 0.0117879 * ($deltaLatitudeToOrigin * 0.00001) ** 5;
1885 3
        $deltaPsi += -0.0055161 * ($deltaLatitudeToOrigin * 0.00001) ** 6;
1886 3
        $deltaPsi += 0.0026906 * ($deltaLatitudeToOrigin * 0.00001) ** 7;
1887 3
        $deltaPsi += -0.001333 * ($deltaLatitudeToOrigin * 0.00001) ** 8;
1888 3
        $deltaPsi += 0.00067 * ($deltaLatitudeToOrigin * 0.00001) ** 9;
1889 3
        $deltaPsi += -0.00034 * ($deltaLatitudeToOrigin * 0.00001) ** 10;
1890
1891 3
        $zeta = new ComplexNumber($deltaPsi, $deltaLongitudeToOrigin->getValue());
1892
1893 3
        $B1 = new ComplexNumber(0.7557853228, 0.0);
1894 3
        $B2 = new ComplexNumber(0.249204646, 0.003371507);
1895 3
        $B3 = new ComplexNumber(-0.001541739, 0.041058560);
1896 3
        $B4 = new ComplexNumber(-0.10162907, 0.01727609);
1897 3
        $B5 = new ComplexNumber(-0.26623489, -0.36249218);
1898 3
        $B6 = new ComplexNumber(-0.6870983, -1.1651967);
1899 3
        $z = new ComplexNumber(0, 0);
1900 3
        $z = $z->add($B1->multiply($zeta->pow(1)));
1901 3
        $z = $z->add($B2->multiply($zeta->pow(2)));
1902 3
        $z = $z->add($B3->multiply($zeta->pow(3)));
1903 3
        $z = $z->add($B4->multiply($zeta->pow(4)));
1904 3
        $z = $z->add($B5->multiply($zeta->pow(5)));
1905 3
        $z = $z->add($B6->multiply($zeta->pow(6)));
1906
1907 3
        $easting = $falseEasting->asMetres()->getValue() + $z->getImaginary() * $a;
1908 3
        $northing = $falseNorthing->asMetres()->getValue() + $z->getReal() * $a;
1909
1910 3
        return ProjectedPoint::create(new Metre($easting), new Metre($northing), new Metre(-$easting), new Metre(-$northing), $to, $this->epoch);
1911
    }
1912
1913
    /**
1914
     * Madrid to ED50 polynomial.
1915
     */
1916 1
    public function madridToED50Polynomial(
1917
        Geographic2D $to,
1918
        Scale $A0,
1919
        Scale $A1,
1920
        Scale $A2,
1921
        Scale $A3,
1922
        Angle $B00,
1923
        Scale $B0,
1924
        Scale $B1,
1925
        Scale $B2,
1926
        Scale $B3
1927
    ): self {
1928 1
        $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());
1929 1
        $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()));
1930
1931 1
        return self::create($this->latitude->add($dLatitude), $this->longitude->add($dLongitude), null, $to, $this->epoch);
1932
    }
1933
1934
    /**
1935
     * Geographic3D to 2D conversion.
1936
     */
1937 1
    public function threeDToTwoD(
1938
        Geographic $to
1939
    ): self {
1940 1
        if ($to instanceof Geographic2D) {
1941 1
            return static::create($this->latitude, $this->longitude, null, $to, $this->epoch);
1942
        }
1943
1944
        return static::create($this->latitude, $this->longitude, new Metre(0), $to, $this->epoch);
1945
    }
1946
1947
    /**
1948
     * Geographic2D offsets.
1949
     * This transformation allows calculation of coordinates in the target system by adding the parameter value to the
1950
     * coordinate values of the point in the source system.
1951
     */
1952 1
    public function geographic2DOffsets(
1953
        Geographic $to,
1954
        Angle $latitudeOffset,
1955
        Angle $longitudeOffset
1956
    ): self {
1957 1
        $toLatitude = $this->latitude->add($latitudeOffset);
1958 1
        $toLongitude = $this->longitude->add($longitudeOffset);
1959
1960 1
        return static::create($toLatitude, $toLongitude, null, $to, $this->epoch);
1961
    }
1962
1963
    /*
1964
     * Geographic2D with Height Offsets.
1965
     * This transformation allows calculation of coordinates in the target system by adding the parameter value to the
1966
     * coordinate values of the point in the source system.
1967
     */
1968
    public function geographic2DWithHeightOffsets(
1969
        Compound $to,
1970
        Angle $latitudeOffset,
1971
        Angle $longitudeOffset,
1972
        Length $geoidUndulation
1973
    ): CompoundPoint {
1974
        $toLatitude = $this->latitude->add($latitudeOffset);
1975
        $toLongitude = $this->longitude->add($longitudeOffset);
1976
        $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

1976
        /** @scrutinizer ignore-call */ 
1977
        $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...
1977
1978
        $horizontal = static::create($toLatitude, $toLongitude, null, $to->getHorizontal(), $this->epoch);
1979
        $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

1979
        $vertical = VerticalPoint::create(/** @scrutinizer ignore-type */ $toHeight, $to->getVertical(), $this->epoch);
Loading history...
1980
1981
        return CompoundPoint::create($horizontal, $vertical, $to, $this->epoch);
1982
    }
1983
1984
    /**
1985
     * General polynomial of degree.
1986
     * @param Coefficient[] $powerCoefficients
1987
     */
1988 2
    public function generalPolynomial(
1989
        Geographic $to,
1990
        Angle $ordinate1OfEvaluationPointInSourceCRS,
1991
        Angle $ordinate2OfEvaluationPointInSourceCRS,
1992
        Angle $ordinate1OfEvaluationPointInTargetCRS,
1993
        Angle $ordinate2OfEvaluationPointInTargetCRS,
1994
        Scale $scalingFactorForSourceCRSCoordDifferences,
1995
        Scale $scalingFactorForTargetCRSCoordDifferences,
1996
        Scale $A0,
1997
        Scale $B0,
1998
        array $powerCoefficients
1999
    ): self {
2000 2
        $xs = $this->latitude->getValue();
2001 2
        $ys = $this->longitude->getValue();
2002
2003 2
        $t = $this->generalPolynomialUnitless(
2004 2
            $xs,
2005
            $ys,
2006
            $ordinate1OfEvaluationPointInSourceCRS,
2007
            $ordinate2OfEvaluationPointInSourceCRS,
2008
            $ordinate1OfEvaluationPointInTargetCRS,
2009
            $ordinate2OfEvaluationPointInTargetCRS,
2010
            $scalingFactorForSourceCRSCoordDifferences,
2011
            $scalingFactorForTargetCRSCoordDifferences,
2012
            $A0,
2013
            $B0,
2014
            $powerCoefficients
2015
        );
2016
2017 2
        $xtUnit = $to->getCoordinateSystem()->getAxes()[0]->getUnitOfMeasureId();
2018 2
        if ($xtUnit === Angle::EPSG_DEGREE_SUPPLIER_TO_DEFINE_REPRESENTATION) {
2019 2
            $xtUnit = Angle::EPSG_DEGREE;
2020
        }
2021 2
        $ytUnit = $to->getCoordinateSystem()->getAxes()[1]->getUnitOfMeasureId();
2022 2
        if ($ytUnit === Angle::EPSG_DEGREE_SUPPLIER_TO_DEFINE_REPRESENTATION) {
2023 2
            $ytUnit = Angle::EPSG_DEGREE;
2024
        }
2025
2026 2
        return static::create(
2027 2
            Angle::makeUnit($t['xt'], $xtUnit),
2028 2
            Angle::makeUnit($t['yt'], $ytUnit),
2029 2
            $this->height,
2030
            $to,
2031 2
            $this->epoch
2032
        );
2033
    }
2034
2035
    /**
2036
     * Reversible polynomial.
2037
     * @param Coefficient[] $powerCoefficients
2038
     */
2039 4
    public function reversiblePolynomial(
2040
        Geographic $to,
2041
        Angle $ordinate1OfEvaluationPoint,
2042
        Angle $ordinate2OfEvaluationPoint,
2043
        Scale $scalingFactorForCoordDifferences,
2044
        Scale $A0,
2045
        Scale $B0,
2046
        $powerCoefficients
2047
    ): self {
2048 4
        $xs = $this->latitude->getValue();
2049 4
        $ys = $this->longitude->getValue();
2050
2051 4
        $t = $this->reversiblePolynomialUnitless(
2052 4
            $xs,
2053
            $ys,
2054
            $ordinate1OfEvaluationPoint,
2055
            $ordinate2OfEvaluationPoint,
2056
            $scalingFactorForCoordDifferences,
2057
            $A0,
2058
            $B0,
2059
            $powerCoefficients
2060
        );
2061
2062 4
        $xtUnit = $to->getCoordinateSystem()->getAxes()[0]->getUnitOfMeasureId();
2063 4
        if ($xtUnit === Angle::EPSG_DEGREE_SUPPLIER_TO_DEFINE_REPRESENTATION) {
2064 4
            $xtUnit = Angle::EPSG_DEGREE;
2065
        }
2066 4
        $ytUnit = $to->getCoordinateSystem()->getAxes()[1]->getUnitOfMeasureId();
2067 4
        if ($ytUnit === Angle::EPSG_DEGREE_SUPPLIER_TO_DEFINE_REPRESENTATION) {
2068 4
            $ytUnit = Angle::EPSG_DEGREE;
2069
        }
2070
2071 4
        return static::create(
2072 4
            Angle::makeUnit($t['xt'], $xtUnit),
2073 4
            Angle::makeUnit($t['yt'], $ytUnit),
2074 4
            $this->height,
2075
            $to,
2076 4
            $this->epoch
2077
        );
2078
    }
2079
2080
    /**
2081
     * Axis Order Reversal.
2082
     */
2083
    public function axisReversal(
2084
        Geographic $to
2085
    ) {
2086
        // axes are read in from the CRS, this is a book-keeping adjustment only
2087
        return static::create($this->latitude, $this->longitude, $this->height, $to, $this->epoch);
2088
    }
2089
2090 10
    public function asGeographicValue(): GeographicValue
2091
    {
2092 10
        return new GeographicValue($this->latitude, $this->longitude, $this->height, $this->crs->getDatum());
2093
    }
2094
}
2095