|
@@ 95-116 (lines=22) @@
|
| 92 |
|
* square. e.g. TG514131. |
| 93 |
|
* @return string |
| 94 |
|
*/ |
| 95 |
|
public function toSixFigureReference() |
| 96 |
|
{ |
| 97 |
|
|
| 98 |
|
$easting = str_pad($this->x, 6, 0, STR_PAD_LEFT); |
| 99 |
|
$northing = str_pad($this->y, 6, 0, STR_PAD_LEFT); |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
$adjustedX = $this->x + 1000000; |
| 103 |
|
$adjustedY = $this->y + 500000; |
| 104 |
|
$majorSquaresEast = floor($adjustedX / 500000); |
| 105 |
|
$majorSquaresNorth = floor($adjustedY / 500000); |
| 106 |
|
$majorLetterIndex = (int)(5 * $majorSquaresNorth + $majorSquaresEast); |
| 107 |
|
$majorLetter = substr(self::GRID_LETTERS, $majorLetterIndex, 1); |
| 108 |
|
|
| 109 |
|
//second (minor) letter is 100km grid sq, origin at 0,0 of this square |
| 110 |
|
$minorSquaresEast = $easting[0] % 5; |
| 111 |
|
$minorSquaresNorth = $northing[0] % 5; |
| 112 |
|
$minorLetterIndex = (int)(5 * $minorSquaresNorth + $minorSquaresEast); |
| 113 |
|
$minorLetter = substr(self::GRID_LETTERS, $minorLetterIndex, 1); |
| 114 |
|
|
| 115 |
|
return $majorLetter . $minorLetter . substr($easting, 1, 3) . substr($northing, 1, 3); |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
/** |
| 119 |
|
* Convert this grid reference into a string using a standard eight-figure |
|
@@ 124-145 (lines=22) @@
|
| 121 |
|
* square. e.g. TG51411311. |
| 122 |
|
* @return string |
| 123 |
|
*/ |
| 124 |
|
public function toEightFigureReference() |
| 125 |
|
{ |
| 126 |
|
|
| 127 |
|
$easting = str_pad($this->x, 6, 0, STR_PAD_LEFT); |
| 128 |
|
$northing = str_pad($this->y, 6, 0, STR_PAD_LEFT); |
| 129 |
|
|
| 130 |
|
|
| 131 |
|
$adjustedX = $this->x + 1000000; |
| 132 |
|
$adjustedY = $this->y + 500000; |
| 133 |
|
$majorSquaresEast = floor($adjustedX / 500000); |
| 134 |
|
$majorSquaresNorth = floor($adjustedY / 500000); |
| 135 |
|
$majorLetterIndex = (int)(5 * $majorSquaresNorth + $majorSquaresEast); |
| 136 |
|
$majorLetter = substr(self::GRID_LETTERS, $majorLetterIndex, 1); |
| 137 |
|
|
| 138 |
|
//second (minor) letter is 100km grid sq, origin at 0,0 of this square |
| 139 |
|
$minorSquaresEast = $easting[0] % 5; |
| 140 |
|
$minorSquaresNorth = $northing[0] % 5; |
| 141 |
|
$minorLetterIndex = (int)(5 * $minorSquaresNorth + $minorSquaresEast); |
| 142 |
|
$minorLetter = substr(self::GRID_LETTERS, $minorLetterIndex, 1); |
| 143 |
|
|
| 144 |
|
return $majorLetter . $minorLetter . substr($easting, 1, 4) . substr($northing, 1, 4); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
/** |
| 148 |
|
* Convert this grid reference into a string using a standard ten-figure |
|
@@ 153-174 (lines=22) @@
|
| 150 |
|
* square. e.g. TG5141213112. |
| 151 |
|
* @return string |
| 152 |
|
*/ |
| 153 |
|
public function toTenFigureReference() |
| 154 |
|
{ |
| 155 |
|
|
| 156 |
|
$easting = str_pad($this->x, 6, 0, STR_PAD_LEFT); |
| 157 |
|
$northing = str_pad($this->y, 6, 0, STR_PAD_LEFT); |
| 158 |
|
|
| 159 |
|
|
| 160 |
|
$adjustedX = $this->x + 1000000; |
| 161 |
|
$adjustedY = $this->y + 500000; |
| 162 |
|
$majorSquaresEast = floor($adjustedX / 500000); |
| 163 |
|
$majorSquaresNorth = floor($adjustedY / 500000); |
| 164 |
|
$majorLetterIndex = (int)(5 * $majorSquaresNorth + $majorSquaresEast); |
| 165 |
|
$majorLetter = substr(self::GRID_LETTERS, $majorLetterIndex, 1); |
| 166 |
|
|
| 167 |
|
//second (minor) letter is 100km grid sq, origin at 0,0 of this square |
| 168 |
|
$minorSquaresEast = $easting[0] % 5; |
| 169 |
|
$minorSquaresNorth = $northing[0] % 5; |
| 170 |
|
$minorLetterIndex = (int)(5 * $minorSquaresNorth + $minorSquaresEast); |
| 171 |
|
$minorLetter = substr(self::GRID_LETTERS, $minorLetterIndex, 1); |
| 172 |
|
|
| 173 |
|
return $majorLetter . $minorLetter . substr($easting, 1, 5) . substr($northing, 1, 5); |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
/** |
| 177 |
|
* Convert this grid reference into a latitude and longitude |