Completed
Push — master ( 3c4a39...ba1925 )
by Doug
02:35
created

UTMRef::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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 string
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 string $latZone
37
     * @param int $lngZone
38
     */
39
    public function __construct($x, $y, $latZone, $lngZone)
40
    {
41
        $this->latZone = $latZone;
42
        $this->lngZone = $lngZone;
0 ignored issues
show
Documentation Bug introduced by
The property $lngZone was declared of type string, but $lngZone is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
43
44
        parent::__construct($x, $y, 0, RefEll::wgs84());
45
    }
46
47
    /**
48
     * @return mixed
49
     */
50
    public function getLatZone()
51
    {
52
        return $this->latZone;
53
    }
54
55
    /**
56
     * @param mixed $latZone
57
     */
58
    public function setLatZone($latZone)
59
    {
60
        $this->latZone = $latZone;
61
    }
62
63
    /**
64
     * @return mixed
65
     */
66
    public function getLngZone()
67
    {
68
        return $this->lngZone;
69
    }
70
71
    /**
72
     * @param mixed $lngZone
73
     */
74
    public function setLngZone($lngZone)
75
    {
76
        $this->lngZone = $lngZone;
77
    }
78
79
80
    public function getReferenceEllipsoid()
81
    {
82
        return RefEll::wgs84();
83
    }
84
85
    public function getScaleFactor()
86
    {
87
        return 0.9996;
88
    }
89
90
    public function getOriginNorthing()
91
    {
92
        return 0;
93
    }
94
95
    public function getOriginEasting()
96
    {
97
        return 500000;
98
    }
99
100
    public function getOriginLatitude()
101
    {
102
        return 0;
103
    }
104
105
    public function getOriginLongitude()
106
    {
107
        return ($this->lngZone - 1) * 6 - 180 + 3;
108
    }
109
110
111
    /**
112
     * Return a string representation of this UTM reference
113
     * @return string
114
     */
115
    public function __toString()
116
    {
117
        return "{$this->lngZone}{$this->latZone} {$this->x} {$this->y}";
118
    }
119
120
    /**
121
     * Convert this UTM reference to a WGS84 latitude and longitude
122
     * @return LatLng
123
     */
124
    public function toLatLng()
125
    {
126
        $N = $this->y;
127
        $E = $this->x;
128
        $N0 = $this->getOriginNorthing();
129
        $E0 = $this->getOriginEasting();
130
        $phi0 = $this->getOriginLatitude();
131
        $lambda0 = $this->getOriginLongitude();
132
133
        //Correct northing for southern hemisphere
134
        if ((ord($this->latZone) - ord("N")) < 0) {
135
            $N -= 10000000;
136
        }
137
138
        return $this->convertToLatitudeLongitude($N, $E, $N0, $E0, $phi0, $lambda0);
139
    }
140
}
141