Passed
Push — 4.x ( f9780c...a64886 )
by Doug
05:20
created

CoordinateReferenceSystem::getSRID()   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 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * PHPCoord.
4
 *
5
 * @author Doug Wright
6
 */
7
declare(strict_types=1);
8
9
namespace PHPCoord\CoordinateReferenceSystem;
10
11
use function array_merge;
12
use PHPCoord\CoordinateSystem\CoordinateSystem;
13
use PHPCoord\Datum\Datum;
14
use PHPCoord\Exception\UnknownCoordinateReferenceSystemException;
15
16
abstract class CoordinateReferenceSystem
17
{
18
    public const CRS_TYPE_COMPOUND = 'compound';
19
20
    public const CRS_TYPE_DERIVED = 'derived';
21
22
    public const CRS_TYPE_DYNAMIC_GEOCENTRIC = 'dynamic geocentric';
23
24
    public const CRS_TYPE_DYNAMIC_GEOGRAPHIC_2D = 'dynamic geographic 2D';
25
26
    public const CRS_TYPE_DYNAMIC_GEOGRAPHIC_3D = 'dynamic geographic 3D';
27
28
    public const CRS_TYPE_DYNAMIC_VERTICAL = 'dynamic vertical';
29
30
    public const CRS_TYPE_ENGINEERING = 'engineering';
31
32
    public const CRS_TYPE_GEOCENTRIC = 'geocentric';
33
34
    public const CRS_TYPE_GEOGRAPHIC_2D = 'geographic 2D';
35
36
    public const CRS_TYPE_GEOGRAPHIC_3D = 'geographic 3D';
37
38
    public const CRS_TYPE_PROJECTED = 'projected';
39
40
    public const CRS_TYPE_VERTICAL = 'vertical';
41
42
    public const CRS_SRID_PREFIX_EPSG = 'urn:ogc:def:crs:EPSG::';
43
44
    protected string $srid;
45
46
    protected CoordinateSystem $coordinateSystem;
47
48
    protected Datum $datum;
49
50 137
    public function getSRID(): string
51
    {
52 137
        return $this->srid;
53
    }
54
55 209
    public function getCoordinateSystem(): CoordinateSystem
56
    {
57 209
        return $this->coordinateSystem;
58
    }
59
60 116
    public function getDatum(): Datum
61
    {
62 116
        return $this->datum;
63
    }
64
65 141
    public static function fromSRID(string $srid): self
66
    {
67 141
        if (isset(Projected::getSupportedSRIDs()[$srid])) {
68 4
            return Projected::fromSRID($srid);
69
        }
70
71 141
        if (isset(Geographic2D::getSupportedSRIDs()[$srid])) {
72 139
            return Geographic2D::fromSRID($srid);
73
        }
74
75 2
        if (isset(Geographic3D::getSupportedSRIDs()[$srid])) {
76 1
            return Geographic3D::fromSRID($srid);
77
        }
78
79 1
        if (isset(Geocentric::getSupportedSRIDs()[$srid])) {
80 1
            return Geocentric::fromSRID($srid);
81
        }
82
83
        if (isset(Vertical::getSupportedSRIDs()[$srid])) {
84
            return Vertical::fromSRID($srid);
85
        }
86
87
        if (isset(Compound::getSupportedSRIDs()[$srid])) {
88
            return Compound::fromSRID($srid);
89
        }
90
91
        throw new UnknownCoordinateReferenceSystemException($srid);
92
    }
93
94
    public static function getSupportedSRIDs(): array
95
    {
96
        return array_merge(Compound::getSupportedSRIDs(), Geocentric::getSupportedSRIDs(), Geographic2D::getSupportedSRIDs(), Geographic3D::getSupportedSRIDs(), Projected::getSupportedSRIDs(), Vertical::getSupportedSRIDs());
97
    }
98
}
99