|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHPCoord. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Doug Wright |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace PHPCoord\CoordinateOperation; |
|
10
|
|
|
|
|
11
|
|
|
use function cos; |
|
12
|
|
|
use PHPCoord\Datum\Datum; |
|
13
|
|
|
use PHPCoord\UnitOfMeasure\Angle\Angle; |
|
14
|
|
|
use PHPCoord\UnitOfMeasure\Angle\Degree; |
|
15
|
|
|
use PHPCoord\UnitOfMeasure\Angle\Radian; |
|
16
|
|
|
use PHPCoord\UnitOfMeasure\Length\Length; |
|
17
|
|
|
use PHPCoord\UnitOfMeasure\Length\Metre; |
|
18
|
|
|
use function sin; |
|
19
|
|
|
use function sqrt; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* A geographic point w/out a CRS. |
|
23
|
|
|
* @internal |
|
24
|
|
|
*/ |
|
25
|
|
|
class GeographicValue |
|
26
|
|
|
{ |
|
27
|
|
|
private Radian $latitude; |
|
28
|
|
|
|
|
29
|
|
|
private Radian $longitude; |
|
30
|
|
|
|
|
31
|
|
|
private ?Metre $height; |
|
32
|
|
|
|
|
33
|
|
|
private Datum $datum; |
|
34
|
|
|
|
|
35
|
48 |
|
public function __construct(Angle $latitude, Angle $longitude, ?Length $height, Datum $datum) |
|
36
|
|
|
{ |
|
37
|
48 |
|
$this->latitude = $this->normaliseLatitude($latitude)->asRadians(); |
|
38
|
48 |
|
$this->longitude = $this->normaliseLongitude($longitude)->asRadians(); |
|
39
|
48 |
|
$this->datum = $datum; |
|
40
|
|
|
|
|
41
|
48 |
|
$this->height = $height ? $height->asMetres() : null; |
|
42
|
48 |
|
} |
|
43
|
|
|
|
|
44
|
44 |
|
public function getLatitude(): Radian |
|
45
|
|
|
{ |
|
46
|
44 |
|
return $this->latitude; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
44 |
|
public function getLongitude(): Radian |
|
50
|
|
|
{ |
|
51
|
44 |
|
return $this->longitude; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
12 |
|
public function getHeight(): ?Metre |
|
55
|
|
|
{ |
|
56
|
12 |
|
return $this->height; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
2 |
|
public function getDatum(): Datum |
|
60
|
|
|
{ |
|
61
|
2 |
|
return $this->datum; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
26 |
|
public function asGeocentricValue(): GeocentricValue |
|
65
|
|
|
{ |
|
66
|
26 |
|
$a = $this->datum->getEllipsoid()->getSemiMajorAxis()->asMetres()->getValue(); |
|
67
|
26 |
|
$e2 = $this->datum->getEllipsoid()->getEccentricitySquared(); |
|
68
|
26 |
|
$latitude = $this->latitude->getValue(); |
|
69
|
26 |
|
$longitude = $this->longitude->getValue() - $this->datum->getPrimeMeridian()->getGreenwichLongitude()->asRadians()->getValue(); |
|
70
|
26 |
|
$h = isset($this->height) ? $this->height->getValue() : 0; |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
26 |
|
$nu = $a / sqrt(1 - $e2 * (sin($latitude) ** 2)); |
|
73
|
26 |
|
$x = ($nu + $h) * cos($latitude) * cos($longitude); |
|
74
|
26 |
|
$y = ($nu + $h) * cos($latitude) * sin($longitude); |
|
75
|
26 |
|
$z = ((1 - $e2) * $nu + $h) * sin($latitude); |
|
76
|
|
|
|
|
77
|
26 |
|
return new GeocentricValue(new Metre($x), new Metre($y), new Metre($z), $this->datum); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
48 |
|
protected function normaliseLatitude(Angle $latitude): Angle |
|
81
|
|
|
{ |
|
82
|
48 |
|
if ($latitude->asDegrees()->getValue() > 90) { |
|
83
|
|
|
return new Degree(90); |
|
84
|
|
|
} |
|
85
|
48 |
|
if ($latitude->asDegrees()->getValue() < -90) { |
|
86
|
|
|
return new Degree(-90); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
48 |
|
return $latitude; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
48 |
|
protected function normaliseLongitude(Angle $longitude): Angle |
|
93
|
|
|
{ |
|
94
|
48 |
|
while ($longitude->asDegrees()->getValue() > 180) { |
|
95
|
1 |
|
$longitude = $longitude->subtract(new Degree(360)); |
|
96
|
|
|
} |
|
97
|
48 |
|
while ($longitude->asDegrees()->getValue() <= -180) { |
|
98
|
|
|
$longitude = $longitude->add(new Degree(360)); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
48 |
|
return $longitude; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
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.