|
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 DateTime; |
|
13
|
|
|
use DateTimeImmutable; |
|
14
|
|
|
use DateTimeInterface; |
|
15
|
|
|
use PHPCoord\CoordinateReferenceSystem\Vertical; |
|
16
|
|
|
use PHPCoord\UnitOfMeasure\Length\Length; |
|
17
|
|
|
use PHPCoord\UnitOfMeasure\Length\Metre; |
|
18
|
|
|
use PHPCoord\UnitOfMeasure\Scale\Scale; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Coordinate representing a vertical dimension. |
|
22
|
|
|
*/ |
|
23
|
|
|
class VerticalPoint extends Point |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Height. |
|
27
|
|
|
*/ |
|
28
|
|
|
protected Length $height; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Coordinate reference system. |
|
32
|
|
|
*/ |
|
33
|
|
|
protected Vertical $crs; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Coordinate epoch (date for which the specified coordinates represented this point). |
|
37
|
|
|
*/ |
|
38
|
|
|
protected ?DateTimeImmutable $epoch; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Constructor. |
|
42
|
|
|
* @param Length $height refer to CRS for preferred unit of measure, but any length unit accepted |
|
43
|
|
|
*/ |
|
44
|
13 |
|
protected function __construct(Length $height, Vertical $crs, ?DateTimeInterface $epoch = null) |
|
45
|
|
|
{ |
|
46
|
13 |
|
$this->height = Length::convert($height, $crs->getCoordinateSystem()->getAxes()[0]->getUnitOfMeasureId()); |
|
47
|
13 |
|
$this->crs = $crs; |
|
48
|
|
|
|
|
49
|
13 |
|
if ($epoch instanceof DateTime) { |
|
50
|
1 |
|
$epoch = DateTimeImmutable::createFromMutable($epoch); |
|
51
|
|
|
} |
|
52
|
13 |
|
$this->epoch = $epoch; |
|
53
|
13 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Constructor. |
|
57
|
|
|
* @param Length $height refer to CRS for preferred unit of measure, but any length unit accepted |
|
58
|
|
|
*/ |
|
59
|
13 |
|
public static function create(Length $height, Vertical $crs, ?DateTimeInterface $epoch = null): self |
|
60
|
|
|
{ |
|
61
|
13 |
|
return new static($height, $crs, $epoch); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
10 |
|
public function getHeight(): Length |
|
65
|
|
|
{ |
|
66
|
10 |
|
return $this->height; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
3 |
|
public function getCRS(): Vertical |
|
70
|
|
|
{ |
|
71
|
3 |
|
return $this->crs; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
3 |
|
public function getCoordinateEpoch(): ?DateTimeImmutable |
|
75
|
|
|
{ |
|
76
|
3 |
|
return $this->epoch; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
public function calculateDistance(Point $to): Length |
|
80
|
|
|
{ |
|
81
|
|
|
/* @var self $to */ |
|
82
|
1 |
|
return new Metre(abs($this->height->asMetres()->getValue() - $to->height->asMetres()->getValue())); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
6 |
|
public function __toString(): string |
|
86
|
|
|
{ |
|
87
|
6 |
|
return "({$this->height})"; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Vertical Offset |
|
92
|
|
|
* This transformation allows calculation of height (or depth) in the target system by adding the parameter value |
|
93
|
|
|
* to the height (or depth)-value of the point in the source system. |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public function verticalOffset( |
|
96
|
|
|
Vertical $to, |
|
97
|
|
|
Length $verticalOffset |
|
98
|
|
|
): self { |
|
99
|
1 |
|
return static::create($this->height->add($verticalOffset), $to); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Height Depth Reversal. |
|
104
|
|
|
*/ |
|
105
|
|
|
public function heightDepthReversal( |
|
106
|
|
|
Vertical $to |
|
107
|
|
|
): self { |
|
108
|
|
|
return static::create($this->height->multiply(-1), $to); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Change of Vertical Unit. |
|
113
|
|
|
*/ |
|
114
|
|
|
public function changeOfVerticalUnit( |
|
115
|
|
|
Vertical $to, |
|
116
|
|
|
Scale $unitConversionScalar |
|
|
|
|
|
|
117
|
|
|
) { |
|
118
|
|
|
// units are auto-converted, don't need to use the supplied param |
|
119
|
|
|
return static::create($this->height, $to, $this->epoch); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.