|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHPCoord |
|
4
|
|
|
* @package PHPCoord |
|
5
|
|
|
* @author Doug Wright |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace PHPCoord; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Irish grid reference (pre-ITM) |
|
11
|
|
|
* References are accurate to 1m |
|
12
|
|
|
* @author Doug Wright |
|
13
|
|
|
* @package PHPCoord |
|
14
|
|
|
*/ |
|
15
|
|
|
class IrishGridRef extends TransverseMercator |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
const GRID_LETTERS = "VWXYZQRSTULMNOPFGHJKABCDE"; |
|
19
|
|
|
|
|
20
|
1 |
|
public function getReferenceEllipsoid() |
|
21
|
|
|
{ |
|
22
|
1 |
|
return RefEll::airyModified(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
1 |
|
public function getScaleFactor() |
|
26
|
|
|
{ |
|
27
|
1 |
|
return 1.000035; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
1 |
|
public function getOriginNorthing() |
|
31
|
|
|
{ |
|
32
|
1 |
|
return 250000; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
1 |
|
public function getOriginEasting() |
|
36
|
|
|
{ |
|
37
|
1 |
|
return 200000; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
1 |
|
public function getOriginLatitude() |
|
41
|
|
|
{ |
|
42
|
1 |
|
return 53.5; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
1 |
|
public function getOriginLongitude() |
|
46
|
|
|
{ |
|
47
|
1 |
|
return -8; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param int $x |
|
52
|
|
|
* @param int $y |
|
53
|
|
|
*/ |
|
54
|
6 |
|
public function __construct($x, $y) |
|
55
|
|
|
{ |
|
56
|
6 |
|
parent::__construct($x, $y, 0, RefEll::airyModified()); |
|
57
|
6 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Take a string formatted as a six-figure grid reference (e.g. |
|
61
|
|
|
* "T514131") and return a reference to an IrishGridRef object that represents |
|
62
|
|
|
* that grid reference. |
|
63
|
|
|
* |
|
64
|
|
|
* @param string $ref |
|
65
|
|
|
* @return OSRef |
|
|
|
|
|
|
66
|
|
|
*/ |
|
67
|
3 |
|
public static function fromSixFigureReference($ref) |
|
68
|
|
|
{ |
|
69
|
|
|
|
|
70
|
3 |
|
$easting = strpos(self::GRID_LETTERS, $ref[0]) % 5 * 100000 + (substr($ref, 1, 3) * 100); |
|
71
|
3 |
|
$northing = (floor(strpos(self::GRID_LETTERS, $ref[0]) / 5)) * 100000 + (substr($ref, 4, 3) * 100); |
|
72
|
|
|
|
|
73
|
3 |
|
return new IrishGridRef($easting, $northing); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Convert this grid reference into a string using a standard six-figure |
|
78
|
|
|
* grid reference including the character designation for the 100km |
|
79
|
|
|
* square. e.g. T514131. |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
1 |
|
public function toSixFigureReference() |
|
83
|
|
|
{ |
|
84
|
|
|
|
|
85
|
1 |
|
$easting = str_pad($this->x, 6, 0, STR_PAD_LEFT); |
|
86
|
1 |
|
$northing = str_pad($this->y, 6, 0, STR_PAD_LEFT); |
|
87
|
|
|
|
|
88
|
|
|
//100km grid sq, origin at 0,0 |
|
89
|
1 |
|
$minorSquaresEast = $easting[0] % 5; |
|
90
|
1 |
|
$minorSquaresNorth = $northing[0] % 5; |
|
91
|
1 |
|
$minorLetterIndex = (int)(5 * $minorSquaresNorth + $minorSquaresEast); |
|
92
|
1 |
|
$minorLetter = substr(self::GRID_LETTERS, $minorLetterIndex, 1); |
|
93
|
|
|
|
|
94
|
1 |
|
return $minorLetter . substr($easting, 1, 3) . substr($northing, 1, 3); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Convert this grid reference into a latitude and longitude |
|
99
|
|
|
* @return LatLng |
|
100
|
|
|
*/ |
|
101
|
1 |
View Code Duplication |
public function toLatLng() |
|
|
|
|
|
|
102
|
|
|
{ |
|
103
|
1 |
|
$N = $this->y; |
|
104
|
1 |
|
$E = $this->x; |
|
105
|
1 |
|
$N0 = $this->getOriginNorthing(); |
|
106
|
1 |
|
$E0 = $this->getOriginEasting(); |
|
107
|
1 |
|
$phi0 = $this->getOriginLatitude(); |
|
108
|
1 |
|
$lambda0 = $this->getOriginLongitude(); |
|
109
|
|
|
|
|
110
|
1 |
|
return $this->convertToLatitudeLongitude($N, $E, $N0, $E0, $phi0, $lambda0); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* String version of coordinate. |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
4 |
|
public function __toString() |
|
118
|
|
|
{ |
|
119
|
4 |
|
return "({$this->x}, {$this->y})"; |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.