Passed
Push — master ( 3e5121...8c57bf )
by Doug
27:00
created

PrimeMeridian::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
c 1
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * PHPCoord.
4
 *
5
 * @author Doug Wright
6
 */
7
declare(strict_types=1);
8
9
namespace PHPCoord\Datum;
10
11
use PHPCoord\Exception\UnknownPrimeMeridianException;
12
use PHPCoord\UnitOfMeasure\Angle\Angle;
13
14
class PrimeMeridian
15
{
16
    /**
17
     * Athens
18
     * Used in Greece for older mapping based on Hatt projection.
19
     */
20
    public const EPSG_ATHENS = 'urn:ogc:def:meridian:EPSG::8912';
21
22
    /**
23
     * Bern
24
     * 1895 value.  Newer value of 7°26'22.335" determined in 1938.
25
     */
26
    public const EPSG_BERN = 'urn:ogc:def:meridian:EPSG::8907';
27
28
    /**
29
     * Bogota.
30
     */
31
    public const EPSG_BOGOTA = 'urn:ogc:def:meridian:EPSG::8904';
32
33
    /**
34
     * Brussels.
35
     */
36
    public const EPSG_BRUSSELS = 'urn:ogc:def:meridian:EPSG::8910';
37
38
    /**
39
     * Ferro
40
     * El Hierro island, Canary islands, considered the most westerly point in Europe. Its longitude has had various
41
     * determinations. 17°40'W of Greenwich was adopted by Austria and former Czechoslovakia, 17°39'46.02"W by former
42
     * Yugoslavia.
43
     */
44
    public const EPSG_FERRO = 'urn:ogc:def:meridian:EPSG::8909';
45
46
    /**
47
     * Greenwich
48
     * The international reference meridian as defined first by the 1884 International Meridian Conference and later by
49
     * the Bureau International de l'Heure (BIH) and then the International Earth Rotation Service (IERS).
50
     */
51
    public const EPSG_GREENWICH = 'urn:ogc:def:meridian:EPSG::8901';
52
53
    /**
54
     * Jakarta
55
     * 1924 determination. Supersedes 1910 value of 106°48'37.05"E of Greenwich.
56
     */
57
    public const EPSG_JAKARTA = 'urn:ogc:def:meridian:EPSG::8908';
58
59
    /**
60
     * Lisbon.
61
     */
62
    public const EPSG_LISBON = 'urn:ogc:def:meridian:EPSG::8902';
63
64
    /**
65
     * Madrid
66
     * Longitude has had various determinations. 3°41'14.55"W of Greenwich adopted for Spanish cartography.
67
     */
68
    public const EPSG_MADRID = 'urn:ogc:def:meridian:EPSG::8905';
69
70
    /**
71
     * Oslo
72
     * Formerly known as Kristiania or Christiania.
73
     */
74
    public const EPSG_OSLO = 'urn:ogc:def:meridian:EPSG::8913';
75
76
    /**
77
     * Paris
78
     * Value adopted by IGN (Paris) in 1936. Equivalent to 2°20'14.025". Preferred by EPSG to earlier value of
79
     * 2°20'13.95" (2.596898 grads) used by RGS London.
80
     */
81
    public const EPSG_PARIS = 'urn:ogc:def:meridian:EPSG::8903';
82
83
    /**
84
     * Paris RGS
85
     * Value replaced by IGN (France) in 1936 - see code 8903. Equivalent to 2.596898 grads.
86
     */
87
    public const EPSG_PARIS_RGS = 'urn:ogc:def:meridian:EPSG::8914';
88
89
    /**
90
     * Rome.
91
     */
92
    public const EPSG_ROME = 'urn:ogc:def:meridian:EPSG::8906';
93
94
    /**
95
     * Stockholm.
96
     */
97
    public const EPSG_STOCKHOLM = 'urn:ogc:def:meridian:EPSG::8911';
98
99
    protected static array $sridData = [
100
        'urn:ogc:def:meridian:EPSG::8901' => [
101
            'name' => 'Greenwich',
102
            'greenwich_longitude' => 0.0,
103
            'uom' => 'urn:ogc:def:uom:EPSG::9102',
104
        ],
105
        'urn:ogc:def:meridian:EPSG::8902' => [
106
            'name' => 'Lisbon',
107
            'greenwich_longitude' => -9.0754862,
108
            'uom' => 'urn:ogc:def:uom:EPSG::9110',
109
        ],
110
        'urn:ogc:def:meridian:EPSG::8903' => [
111
            'name' => 'Paris',
112
            'greenwich_longitude' => 2.5969213,
113
            'uom' => 'urn:ogc:def:uom:EPSG::9105',
114
        ],
115
        'urn:ogc:def:meridian:EPSG::8904' => [
116
            'name' => 'Bogota',
117
            'greenwich_longitude' => -74.04513,
118
            'uom' => 'urn:ogc:def:uom:EPSG::9110',
119
        ],
120
        'urn:ogc:def:meridian:EPSG::8905' => [
121
            'name' => 'Madrid',
122
            'greenwich_longitude' => -3.411455,
123
            'uom' => 'urn:ogc:def:uom:EPSG::9110',
124
        ],
125
        'urn:ogc:def:meridian:EPSG::8906' => [
126
            'name' => 'Rome',
127
            'greenwich_longitude' => 12.27084,
128
            'uom' => 'urn:ogc:def:uom:EPSG::9110',
129
        ],
130
        'urn:ogc:def:meridian:EPSG::8907' => [
131
            'name' => 'Bern',
132
            'greenwich_longitude' => 7.26225,
133
            'uom' => 'urn:ogc:def:uom:EPSG::9110',
134
        ],
135
        'urn:ogc:def:meridian:EPSG::8908' => [
136
            'name' => 'Jakarta',
137
            'greenwich_longitude' => 106.482779,
138
            'uom' => 'urn:ogc:def:uom:EPSG::9110',
139
        ],
140
        'urn:ogc:def:meridian:EPSG::8909' => [
141
            'name' => 'Ferro',
142
            'greenwich_longitude' => -17.4,
143
            'uom' => 'urn:ogc:def:uom:EPSG::9110',
144
        ],
145
        'urn:ogc:def:meridian:EPSG::8910' => [
146
            'name' => 'Brussels',
147
            'greenwich_longitude' => 4.220471,
148
            'uom' => 'urn:ogc:def:uom:EPSG::9110',
149
        ],
150
        'urn:ogc:def:meridian:EPSG::8911' => [
151
            'name' => 'Stockholm',
152
            'greenwich_longitude' => 18.03298,
153
            'uom' => 'urn:ogc:def:uom:EPSG::9110',
154
        ],
155
        'urn:ogc:def:meridian:EPSG::8912' => [
156
            'name' => 'Athens',
157
            'greenwich_longitude' => 23.4258815,
158
            'uom' => 'urn:ogc:def:uom:EPSG::9110',
159
        ],
160
        'urn:ogc:def:meridian:EPSG::8913' => [
161
            'name' => 'Oslo',
162
            'greenwich_longitude' => 10.43225,
163
            'uom' => 'urn:ogc:def:uom:EPSG::9110',
164
        ],
165
        'urn:ogc:def:meridian:EPSG::8914' => [
166
            'name' => 'Paris RGS',
167
            'greenwich_longitude' => 2.201395,
168
            'uom' => 'urn:ogc:def:uom:EPSG::9110',
169
        ],
170
    ];
171
172
    private static array $cachedObjects = [];
173
174
    private string $name;
175
176
    private Angle $greenwichLongitude;
177
178
    public function __construct(string $name, Angle $greenwichLongitude)
179
    {
180
        $this->name = $name;
181
        $this->greenwichLongitude = $greenwichLongitude;
182
    }
183
184 9
    public function getName(): string
185
    {
186 9
        return $this->name;
187
    }
188
189 436
    public function getGreenwichLongitude(): Angle
190
    {
191 436
        return $this->greenwichLongitude;
192
    }
193
194 661
    public static function fromSRID(string $srid): self
195
    {
196 661
        if (!isset(static::$sridData[$srid])) {
197 9
            throw new UnknownPrimeMeridianException($srid);
198
        }
199
200 652
        if (!isset(self::$cachedObjects[$srid])) {
201
            $data = static::$sridData[$srid];
202
203
            self::$cachedObjects[$srid] = new static($data['name'], Angle::makeUnit($data['greenwich_longitude'], $data['uom']));
204
        }
205
206 652
        return self::$cachedObjects[$srid];
207
    }
208
209 9
    public static function getSupportedSRIDs(): array
210
    {
211 9
        $supported = [];
212 9
        foreach (static::$sridData as $srid => $data) {
213 9
            $supported[$srid] = $data['name'];
214
        }
215
216 9
        return $supported;
217
    }
218
}
219