getNorthingFromChar static method Null safety
Given the second letter from a two-letter MGRS 100k zone, and given the MGRS table set for the zone number, figure out the northing value that should be added to the other, secondary northing value. You have to remember that Northings are determined from the equator, and the vertical cycle of letters mean a 2000000 additional northing meters. This happens approx. every 18 degrees of latitude. This method does NOT count any additional northings. You have to figure out how many 2000000 meters need to be added for the zone letter of the MGRS coordinate.
@private @param {string} n Second letter of the MGRS 100k zone @param {number} set The MGRS table set number, which is dependent on the UTM zone number. @return {number} The northing value for the given letter and set.
Implementation
static int getNorthingFromChar(String n, int set) {
if (ALPHABET.indexOf(n.toLowerCase()) >
ALPHABET.indexOf('V'.toLowerCase())) {
throw Exception('MGRSPoint given invalid Northing $n');
}
// rowOrigin is the letter at the origin of the set for the
// column
var curRow = unicode.toRune(SET_ORIGIN_ROW_LETTERS[set - 1]);
var northingValue = 0;
var rewindMarker = false;
while (curRow != unicode.toRune(n[0])) {
curRow++;
if (curRow == I) {
curRow++;
}
if (curRow == O) {
curRow++;
}
// fixing a bug making whole application hang in this loop
// when 'n' is a wrong character
if (curRow > V) {
if (rewindMarker) {
// making sure that this loop ends
throw Exception('Bad character: $n');
}
curRow = A;
rewindMarker = true;
}
northingValue += 100000;
}
return northingValue;
}