| @@ 124-153 (lines=30) @@ | ||
| 121 | * square. e.g. TG51411311. |
|
| 122 | * @return string |
|
| 123 | */ |
|
| 124 | public function toEightFigureString() |
|
| 125 | { |
|
| 126 | ||
| 127 | $easting = str_pad($this->easting, 6, 0, STR_PAD_LEFT); |
|
| 128 | $northing = str_pad($this->northing, 6, 0, STR_PAD_LEFT); |
|
| 129 | ||
| 130 | $hundredkmE = $easting[0]; |
|
| 131 | $hundredkmN = $northing[0]; |
|
| 132 | ||
| 133 | if ($hundredkmN < 5 && $hundredkmE < 5) { |
|
| 134 | $firstLetter = 'S'; |
|
| 135 | } else if ($hundredkmN < 5 && $hundredkmE >= 5) { |
|
| 136 | $firstLetter = 'T'; |
|
| 137 | } else if ($hundredkmN < 10 && $hundredkmE < 5) { |
|
| 138 | $firstLetter = 'N'; |
|
| 139 | } else if ($hundredkmN < 10 && $hundredkmE >= 5) { |
|
| 140 | $firstLetter = 'O'; |
|
| 141 | } else { |
|
| 142 | $firstLetter = 'H'; |
|
| 143 | } |
|
| 144 | ||
| 145 | $index = 65 + ((4 - ($hundredkmN % 5)) * 5) + ($hundredkmE % 5); |
|
| 146 | if ($index >= 73) { |
|
| 147 | //skip the letter I |
|
| 148 | $index++; |
|
| 149 | } |
|
| 150 | $secondLetter = chr($index); |
|
| 151 | ||
| 152 | return $firstLetter . $secondLetter . substr($easting, 1, 4) . substr($northing, 1, 4); |
|
| 153 | } |
|
| 154 | ||
| 155 | /** |
|
| 156 | * Convert this grid reference into a string using a standard ten-figure |
|
| @@ 161-190 (lines=30) @@ | ||
| 158 | * square. e.g. TG5141213112. |
|
| 159 | * @return string |
|
| 160 | */ |
|
| 161 | public function toTenFigureString() |
|
| 162 | { |
|
| 163 | ||
| 164 | $easting = str_pad($this->easting, 6, 0, STR_PAD_LEFT); |
|
| 165 | $northing = str_pad($this->northing, 6, 0, STR_PAD_LEFT); |
|
| 166 | ||
| 167 | $hundredkmE = $easting[0]; |
|
| 168 | $hundredkmN = $northing[0]; |
|
| 169 | ||
| 170 | if ($hundredkmN < 5 && $hundredkmE < 5) { |
|
| 171 | $firstLetter = 'S'; |
|
| 172 | } else if ($hundredkmN < 5 && $hundredkmE >= 5) { |
|
| 173 | $firstLetter = 'T'; |
|
| 174 | } else if ($hundredkmN < 10 && $hundredkmE < 5) { |
|
| 175 | $firstLetter = 'N'; |
|
| 176 | } else if ($hundredkmN < 10 && $hundredkmE >= 5) { |
|
| 177 | $firstLetter = 'O'; |
|
| 178 | } else { |
|
| 179 | $firstLetter = 'H'; |
|
| 180 | } |
|
| 181 | ||
| 182 | $index = 65 + ((4 - ($hundredkmN % 5)) * 5) + ($hundredkmE % 5); |
|
| 183 | if ($index >= 73) { |
|
| 184 | //skip the letter I |
|
| 185 | $index++; |
|
| 186 | } |
|
| 187 | $secondLetter = chr($index); |
|
| 188 | ||
| 189 | return $firstLetter . $secondLetter . substr($easting, 1, 5) . substr($northing, 1, 5); |
|
| 190 | } |
|
| 191 | ||
| 192 | /** |
|
| 193 | * Convert this grid reference into a latitude and longitude |
|