Skip to content

Commit

Permalink
play with mgrs coordinates; not quite working yet
Browse files Browse the repository at this point in the history
  • Loading branch information
jillesvangurp committed Nov 14, 2023
1 parent b753eac commit e4c1a2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/commonMain/kotlin/com/jillesvangurp/geo/mgrs.kt
Expand Up @@ -19,6 +19,12 @@ data class MgrsCoordinate(
}
}

/**
* Half working implementation based of chat gpt. Don't use this.
*
* TODO find better implementation
*
*/
fun UtmCoordinate.convertUTMToMGRS(): MgrsCoordinate {
val eastingLetter = getEastingLetter(longitudeZone, easting.toInt())
val northingLetter = getNorthingLetter(northing.toInt(), latitudeZoneLetter)
Expand All @@ -42,12 +48,9 @@ private fun getEastingLetter(zoneNumber: Int, easting: Int): Char {
return eastingLetters[index]
}

//private fun getNorthingLetter(zoneNumber: Int, northing: Int): Char {
// val gridNorthing = (northing / 100000)
// val index = (gridNorthing - 1 + (zoneNumber - 1) * 2) % northingLetters.length
// return northingLetters[index]
//}

/**
* This is wrong.
*/
private fun getNorthingLetter(northing: Int, latitudeZoneLetter: Char): Char {
// Northing value should be adjusted for the false northing if in the southern hemisphere.
val adjustedNorthing = if (latitudeZoneLetter < 'N') northing + 10000000 else northing
Expand All @@ -57,6 +60,11 @@ private fun getNorthingLetter(northing: Int, latitudeZoneLetter: Char): Char {
}


/**
* Half working implementation based of chat gpt. Don't use this.
*
* TODO find better implementation
*/
fun convertMGRSToUTM(
zoneNumber: Int,
zoneLetter: Char,
Expand Down
Expand Up @@ -275,6 +275,8 @@ class UTMTest {
(utmCalculated.northing - testCase.utm.northing).absoluteValue shouldBeLessThan 10.0
}
}

println("${testCase.name} ${testCase.point.latitude},${testCase.point.longitude} -> ${utmCalculated.convertUTMToMGRS()}")
}
} else {
// reserve for test cases that aren't working
Expand Down

0 comments on commit e4c1a2d

Please sign in to comment.