|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHPCoord. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Doug Wright |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace PHPCoord\UnitOfMeasure; |
|
10
|
|
|
|
|
11
|
|
|
use PHPCoord\Exception\InvalidRateException; |
|
12
|
|
|
use PHPCoord\Exception\UnknownUnitOfMeasureException; |
|
13
|
|
|
use PHPCoord\UnitOfMeasure\Angle\Angle; |
|
14
|
|
|
use PHPCoord\UnitOfMeasure\Angle\ArcSecond; |
|
15
|
|
|
use PHPCoord\UnitOfMeasure\Length\Centimetre; |
|
16
|
|
|
use PHPCoord\UnitOfMeasure\Length\Metre; |
|
17
|
|
|
use PHPCoord\UnitOfMeasure\Length\Millimetre; |
|
18
|
|
|
use PHPCoord\UnitOfMeasure\Scale\PartsPerBillion; |
|
19
|
|
|
use PHPCoord\UnitOfMeasure\Scale\PartsPerMillion; |
|
20
|
|
|
use PHPCoord\UnitOfMeasure\Time\Time; |
|
21
|
|
|
use PHPCoord\UnitOfMeasure\Time\Year; |
|
22
|
|
|
|
|
23
|
|
|
class Rate implements UnitOfMeasure |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* arc-seconds per year |
|
27
|
|
|
* =((pi/180) / 3600) radians per year. Year taken to be IUGS definition of 31556925.445 seconds; see UoM code |
|
28
|
|
|
* 1029. |
|
29
|
|
|
*/ |
|
30
|
|
|
public const EPSG_ARC_SECONDS_PER_YEAR = 'urn:ogc:def:uom:EPSG::1043'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* centimetres per year |
|
34
|
|
|
* Year taken to be IUGS definition of 31556925.445 seconds; see UoM code 1029. |
|
35
|
|
|
*/ |
|
36
|
|
|
public const EPSG_CENTIMETRES_PER_YEAR = 'urn:ogc:def:uom:EPSG::1034'; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* metres per year |
|
40
|
|
|
* Year taken to be IUGS definition of 31556925.445 seconds; see UoM code 1029. |
|
41
|
|
|
*/ |
|
42
|
|
|
public const EPSG_METRES_PER_YEAR = 'urn:ogc:def:uom:EPSG::1042'; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* milliarc-seconds per year |
|
46
|
|
|
* = ((pi/180) / 3600 / 1000) radians per year. Year taken to be IUGS definition of 31556925.445 seconds; see UoM |
|
47
|
|
|
* code 1029. |
|
48
|
|
|
*/ |
|
49
|
|
|
public const EPSG_MILLIARC_SECONDS_PER_YEAR = 'urn:ogc:def:uom:EPSG::1032'; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* millimetres per year |
|
53
|
|
|
* Year taken to be IUGS definition of 31556925.445 seconds; see UoM code 1029. |
|
54
|
|
|
*/ |
|
55
|
|
|
public const EPSG_MILLIMETRES_PER_YEAR = 'urn:ogc:def:uom:EPSG::1027'; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* parts per billion per year |
|
59
|
|
|
* Year taken to be IUGS definition of 31556925.445 seconds; see UoM code 1029. Billion is internationally |
|
60
|
|
|
* ambiguous, in different languages being 1E+9 and 1E+12. One billion taken here to be 1E+9. |
|
61
|
|
|
*/ |
|
62
|
|
|
public const EPSG_PARTS_PER_BILLION_PER_YEAR = 'urn:ogc:def:uom:EPSG::1030'; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* parts per million per year |
|
66
|
|
|
* Year taken to be IUGS definition of 31556925.445 seconds; see UoM code 1029. |
|
67
|
|
|
*/ |
|
68
|
|
|
public const EPSG_PARTS_PER_MILLION_PER_YEAR = 'urn:ogc:def:uom:EPSG::1041'; |
|
69
|
|
|
|
|
70
|
|
|
protected static array $sridData = [ |
|
71
|
|
|
'urn:ogc:def:uom:EPSG::1027' => [ |
|
72
|
|
|
'name' => 'millimetres per year', |
|
73
|
|
|
], |
|
74
|
|
|
'urn:ogc:def:uom:EPSG::1030' => [ |
|
75
|
|
|
'name' => 'parts per billion per year', |
|
76
|
|
|
], |
|
77
|
|
|
'urn:ogc:def:uom:EPSG::1032' => [ |
|
78
|
|
|
'name' => 'milliarc-seconds per year', |
|
79
|
|
|
], |
|
80
|
|
|
'urn:ogc:def:uom:EPSG::1034' => [ |
|
81
|
|
|
'name' => 'centimetres per year', |
|
82
|
|
|
], |
|
83
|
|
|
'urn:ogc:def:uom:EPSG::1041' => [ |
|
84
|
|
|
'name' => 'parts per million per year', |
|
85
|
|
|
], |
|
86
|
|
|
'urn:ogc:def:uom:EPSG::1042' => [ |
|
87
|
|
|
'name' => 'metres per year', |
|
88
|
|
|
], |
|
89
|
|
|
'urn:ogc:def:uom:EPSG::1043' => [ |
|
90
|
|
|
'name' => 'arc-seconds per year', |
|
91
|
|
|
], |
|
92
|
|
|
]; |
|
93
|
|
|
|
|
94
|
|
|
private UnitOfMeasure $change; |
|
95
|
|
|
|
|
96
|
|
|
private Time $time; |
|
97
|
|
|
|
|
98
|
|
|
private static array $supportedCache = []; |
|
99
|
|
|
|
|
100
|
1192 |
|
public function __construct(UnitOfMeasure $change, Time $time) |
|
101
|
|
|
{ |
|
102
|
1192 |
|
if ($change instanceof Time) { |
|
103
|
|
|
throw new InvalidRateException('A rate is a change per unit of time, the change cannot be time'); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
1192 |
|
$this->change = $change; |
|
107
|
1192 |
|
$this->time = $time; |
|
108
|
1192 |
|
} |
|
109
|
|
|
|
|
110
|
9 |
|
public function getChange(): UnitOfMeasure |
|
111
|
|
|
{ |
|
112
|
9 |
|
return $this->change; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
1030 |
|
public function getChangePerYear(): UnitOfMeasure |
|
116
|
|
|
{ |
|
117
|
1030 |
|
return $this->change->divide($this->time->asYears()->getValue()); |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
9 |
|
public function getTime(): Time |
|
121
|
|
|
{ |
|
122
|
9 |
|
return $this->time; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
18 |
|
public function getValue(): float |
|
126
|
|
|
{ |
|
127
|
18 |
|
return $this->change->getValue(); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
9 |
|
public function getUnitName(): string |
|
131
|
|
|
{ |
|
132
|
9 |
|
return $this->change->getUnitName() . ' per ' . $this->time->getUnitName(); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
9 |
|
public function __toString(): string |
|
136
|
|
|
{ |
|
137
|
9 |
|
return (string) $this->getValue(); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
1147 |
|
public static function makeUnit(float $measurement, string $srid): self |
|
141
|
|
|
{ |
|
142
|
1147 |
|
if (!isset(static::$sridData[$srid])) { |
|
143
|
9 |
|
throw new UnknownUnitOfMeasureException($srid); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
return match ($srid) { |
|
147
|
1138 |
|
self::EPSG_ARC_SECONDS_PER_YEAR => new self(new ArcSecond($measurement), new Year(1)), |
|
148
|
45 |
|
self::EPSG_MILLIARC_SECONDS_PER_YEAR => new self(Angle::makeUnit($measurement, Angle::EPSG_MILLIARC_SECOND), new Year(1)), |
|
149
|
1120 |
|
self::EPSG_METRES_PER_YEAR => new self(new Metre($measurement), new Year(1)), |
|
150
|
1003 |
|
self::EPSG_MILLIMETRES_PER_YEAR => new self(new Millimetre($measurement), new Year(1)), |
|
151
|
1102 |
|
self::EPSG_CENTIMETRES_PER_YEAR => new self(new Centimetre($measurement), new Year(1)), |
|
152
|
208 |
|
self::EPSG_PARTS_PER_BILLION_PER_YEAR => new self(new PartsPerBillion($measurement), new Year(1)), |
|
153
|
1084 |
|
self::EPSG_PARTS_PER_MILLION_PER_YEAR => new self(new PartsPerMillion($measurement), new Year(1)), |
|
154
|
661 |
|
default => throw new UnknownUnitOfMeasureException($srid), |
|
155
|
1066 |
|
}; |
|
156
|
198 |
|
} |
|
157
|
1048 |
|
|
|
158
|
1003 |
|
public static function getSupportedSRIDs(): array |
|
159
|
45 |
|
{ |
|
160
|
45 |
|
if (!self::$supportedCache) { |
|
|
|
|
|
|
161
|
|
|
foreach (static::$sridData as $srid => $data) { |
|
162
|
|
|
self::$supportedCache[$srid] = $data['name']; |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
18 |
|
return self::$supportedCache; |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|