getLetter100kID static method Null safety
Get the two-letter MGRS 100k designator given information translated from the UTM northing, easting and zone number.
@private @param {number} column the column index as it relates to the MGRS 100k set spreadsheet, created from the UTM easting. Values are 1-8. @param {number} row the row index as it relates to the MGRS 100k set spreadsheet, created from the UTM northing value. Values are from 0-19. @param {number} parm the set block, as it relates to the MGRS 100k set spreadsheet, created from the UTM zone. Values are from 1-60. @return {string} two letter MGRS 100k code.
Implementation
static String getLetter100kID(int column, int row, int parm) {
// colOrigin and rowOrigin are the letters at the origin of the set
var index = parm - 1;
var colOrigin = unicode.toRune(SET_ORIGIN_COLUMN_LETTERS[index]);
var rowOrigin = unicode.toRune(SET_ORIGIN_ROW_LETTERS[index]);
// colInt and rowInt are the letters to build to return
var colInt = colOrigin + column - 1;
var rowInt = rowOrigin + row;
var rollover = false;
if (colInt > Z) {
colInt = colInt - Z + A - 1;
rollover = true;
}
if (colInt == I ||
(colOrigin < I && colInt > I) ||
((colInt > I || colOrigin < I) && rollover)) {
colInt++;
}
if (colInt == O ||
(colOrigin < O && colInt > O) ||
((colInt > O || colOrigin < O) && rollover)) {
colInt++;
if (colInt == I) {
colInt++;
}
}
if (colInt > Z) {
colInt = colInt - Z + A - 1;
}
if (rowInt > V) {
rowInt = rowInt - V + A - 1;
rollover = true;
} else {
rollover = false;
}
if (((rowInt == I) || ((rowOrigin < I) && (rowInt > I))) ||
(((rowInt > I) || (rowOrigin < I)) && rollover)) {
rowInt++;
}
if (((rowInt == O) || ((rowOrigin < O) && (rowInt > O))) ||
(((rowInt > O) || (rowOrigin < O)) && rollover)) {
rowInt++;
if (rowInt == I) {
rowInt++;
}
}
if (rowInt > V) {
rowInt = rowInt - V + A - 1;
}
var twoLetter =
'${String.fromCharCode(colInt)}${String.fromCharCode(rowInt)}';
return twoLetter;
}