|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHPCoord. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Doug Wright |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace PHPCoord; |
|
10
|
|
|
|
|
11
|
|
|
use PHPCoord\CoordinateReferenceSystem\Compound; |
|
12
|
|
|
use PHPCoord\CoordinateReferenceSystem\CoordinateReferenceSystem; |
|
13
|
|
|
use PHPCoord\Exception\InvalidCoordinateReferenceSystemException; |
|
14
|
|
|
use PHPCoord\UnitOfMeasure\Length\Length; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Coordinate representing a point expressed in 2 different CRSs (2D horizontal + 1D Vertical). |
|
18
|
|
|
*/ |
|
19
|
|
|
class CompoundPoint extends Point |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Horizontal point. |
|
23
|
|
|
* @var GeocentricPoint|GeographicPoint|ProjectedPoint |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $horizontalPoint; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Vertical point. |
|
29
|
|
|
* @var VerticalPoint |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $verticalPoint; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Coordinate reference system. |
|
35
|
|
|
* @var CoordinateReferenceSystem |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $crs; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Constructor. |
|
41
|
|
|
* @param GeocentricPoint|GeographicPoint|ProjectedPoint $horizontalPoint |
|
42
|
|
|
*/ |
|
43
|
4 |
|
public function __construct(Point $horizontalPoint, VerticalPoint $verticalPoint, CoordinateReferenceSystem $crs) |
|
44
|
|
|
{ |
|
45
|
4 |
|
if (!$crs instanceof Compound) { |
|
46
|
1 |
|
throw new InvalidCoordinateReferenceSystemException(sprintf("A compound point must be associated with a compound CRS, but a '%s' CRS was given", get_class($crs))); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
3 |
|
$this->horizontalPoint = $horizontalPoint; |
|
|
|
|
|
|
50
|
3 |
|
$this->verticalPoint = $verticalPoint; |
|
51
|
3 |
|
$this->crs = $crs; |
|
52
|
3 |
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
public function getHorizontalPoint(): Point |
|
55
|
|
|
{ |
|
56
|
1 |
|
return $this->horizontalPoint; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
public function getVerticalPoint(): VerticalPoint |
|
60
|
|
|
{ |
|
61
|
1 |
|
return $this->verticalPoint; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
3 |
|
public function getCRS(): CoordinateReferenceSystem |
|
65
|
|
|
{ |
|
66
|
3 |
|
return $this->crs; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Calculate distance between two points. |
|
71
|
|
|
*/ |
|
72
|
2 |
|
public function calculateDistance(Point $to): Length |
|
73
|
|
|
{ |
|
74
|
2 |
|
if ($to->getCRS()->getEpsgCode() !== $this->crs->getEpsgCode()) { |
|
75
|
1 |
|
throw new InvalidCoordinateReferenceSystemException('Can only calculate distances between two points in the same CRS'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/* @var CompoundPoint $to */ |
|
79
|
1 |
|
return $this->horizontalPoint->calculateDistance($to->horizontalPoint); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
1 |
|
public function __toString(): string |
|
83
|
|
|
{ |
|
84
|
1 |
|
return "({$this->horizontalPoint}, {$this->verticalPoint})"; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.