Completed
Push — master ( 89e8f9...491935 )
by Doug
08:18
created

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