Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for BNG quadrant identifiers #580

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ object BNGIndexSystem extends IndexSystem(StringType) with Serializable {
encode(eLetter, 0, 0, 0, 0, 1, -1)
} else {
val suffix = index.slice(index.length - 2, index.length)
val quadrant: Int = if (quadrants.contains(suffix)) quadrants.indexOf(suffix) else 0
val quadrant: Int = if (quadrants.contains(suffix) && index.length > 2) quadrants.indexOf(suffix) else 0
val binDigits = if (quadrant > 0) index.drop(2).dropRight(2) else index.drop(2)
if (binDigits.isEmpty) {
encode(eLetter, nLetter, 0, 0, quadrant, 1, -2)
Expand Down Expand Up @@ -537,7 +537,7 @@ object BNGIndexSystem extends IndexSystem(StringType) with Serializable {
math.abs((x1 - x2) / edgeSize) + math.abs((y1 - y2) / edgeSize)
}

private def encode(eLetter: Int, nLetter: Int, eBin: Int, nBin: Int, quadrant: Int, nPositions: Int, resolution: Int): Long = {
def encode(eLetter: Int, nLetter: Int, eBin: Int, nBin: Int, quadrant: Int, nPositions: Int, resolution: Int): Long = {
val idPlaceholder = math.pow(10, 5 + 2 * nPositions - 2) // 1(##)(##)(#...#)(#...#)(#)
val eLetterShift = math.pow(10, 3 + 2 * nPositions - 2) // (##)(##)(#...#)(#...#)(#)
val nLetterShift = math.pow(10, 1 + 2 * nPositions - 2) // (##)(#...#)(#...#)(#)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class TestBNGIndexSystem extends AnyFunSuite {
BNGIndexSystem.parse("TQ") shouldBe 105010
BNGIndexSystem.format(105010) shouldBe "TQ"

BNGIndexSystem.parse("NW") shouldBe BNGIndexSystem.encode(1, 5, 0, 0, 0, 1, -2)
BNGIndexSystem.format(105010) shouldBe "TQ"

BNGIndexSystem.parse("TQNW") shouldBe 105012
BNGIndexSystem.format(105012) shouldBe "TQNW"

Expand Down
Loading