Completed
Branch 3.0-dev (e499db)
by Doug
02:12
created

UTMRef::getLatZone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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