Last active
March 16, 2021 14:21
-
-
Save valgur/e647354c600a43b8aebd81578821c7f7 to your computer and use it in GitHub Desktop.
Estonian Land Board map sheet (grid) index formulas / Maa-ameti kaardilehtede järjekorranumbrite teisendusvalemid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# x - easting, y - northing | |
def grid20k(x, y): | |
x = int(x) // 1000 - 200 | |
y = int(y) // 1000 - 5900 | |
idx = (y // 100) * 1000 + (y // 10 % 10) * 10 | |
idx += (x // 100) * 100 + (x // 10 % 10) | |
return idx | |
def grid10k(x, y): | |
idx = grid20k(x, y) * 10 | |
idx += (int(y) // 5000 % 2) * 2 | |
idx += (int(x) // 5000 % 2) + 1 | |
return idx | |
def grid2k(x, y): | |
return (int(y / 1000) - 6000) * 1000 + int(x / 1000) | |
def decode_grid20k(idx): | |
x = ((idx // 100) % 10) * 10 | |
x += idx % 10 | |
y = (idx // 1000) * 10 | |
y += (idx // 10) % 10 | |
return (x + 20) * 10000, (y + 590) * 10000 | |
def decode_grid10k(idx): | |
x, y = decode_grid20k(idx // 10) | |
sub_idx = idx % 10 - 1 | |
x += (sub_idx % 2) * 5000 | |
y += (sub_idx // 2) * 5000 | |
return x, y | |
def decode_grid2k(idx): | |
return idx % 1000 * 1000, (idx // 1000 + 6000) * 1000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment