Completed
Push — master ( 4c6b8b...d48a1a )
by Doug
03:34
created

UTMRef::getOriginLatitude()   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
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PHPCoord;
6
7
use function ord;
8
9
/**
10
 * UTM reference.
11
 * @author Jonathan Stott
12
 * @author Doug Wright
13
 */
14
class UTMRef extends TransverseMercator
15
{
16
    /**
17
     * Latitude zone.
18
     * @var string
19
     */
20
    protected $latZone;
21
22
    /**
23
     * Longitude zone.
24
     * @var int
25
     */
26
    protected $lngZone;
27
28
    /**
29
     * Create a new object representing a UTM reference.
30
     *
31
     * @param int    $x
32
     * @param int    $y
33
     * @param int    $z
34
     * @param string $latZone
35
     * @param int    $lngZone
36
     */
37 5
    public function __construct(int $x, int $y, int $z, string $latZone, int $lngZone)
38
    {
39 5
        $this->latZone = $latZone;
40 5
        $this->lngZone = $lngZone;
41
42 5
        parent::__construct($x, $y, $z, RefEll::wgs84());
43 5
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getLatZone(): string
49
    {
50
        return $this->latZone;
51
    }
52
53
    /**
54
     * @return int
55
     */
56
    public function getLngZone(): int
57
    {
58
        return $this->lngZone;
59
    }
60
61
    /**
62
     * @return RefEll
63
     */
64 2
    public function getReferenceEllipsoid(): RefEll
65
    {
66 2
        return RefEll::wgs84();
67
    }
68
69
    /**
70
     * @return float
71
     */
72 4
    public function getScaleFactor(): float
73
    {
74 4
        return 0.9996;
75
    }
76
77
    /**
78
     * @return int
79
     */
80 4
    public function getOriginNorthing(): int
81
    {
82 4
        return 0;
83
    }
84
85
    /**
86
     * @return int
87
     */
88 4
    public function getOriginEasting(): int
89
    {
90 4
        return 500000;
91
    }
92
93
    /**
94
     * @return float
95
     */
96 4
    public function getOriginLatitude(): float
97
    {
98 4
        return 0;
99
    }
100
101
    /**
102
     * @return float
103
     */
104 4
    public function getOriginLongitude(): float
105
    {
106 4
        return ($this->lngZone - 1) * 6 - 180 + 3;
107
    }
108
109
    /**
110
     * Return a string representation of this UTM reference.
111
     * @return string
112
     */
113 3
    public function __toString(): string
114
    {
115 3
        return "{$this->lngZone}{$this->latZone} {$this->x} {$this->y}";
116
    }
117
118
    /**
119
     * Convert this UTM reference to a WGS84 latitude and longitude.
120
     * @return LatLng
121
     */
122 2
    public function toLatLng(): LatLng
123
    {
124 2
        $N = $this->y;
125 2
        $E = $this->x;
126 2
        $N0 = $this->getOriginNorthing();
127 2
        $E0 = $this->getOriginEasting();
128 2
        $phi0 = $this->getOriginLatitude();
129 2
        $lambda0 = $this->getOriginLongitude();
130
131
        //Correct northing for southern hemisphere
132 2
        if ((ord($this->latZone) - ord('N')) < 0) {
133 1
            $N -= 10000000;
134
        }
135
136 2
        return $this->convertToLatitudeLongitude($N, $E, $N0, $E0, $phi0, $lambda0);
137
    }
138
}
139