Skip to content

Instantly share code, notes, and snippets.

@valgur
Last active March 16, 2021 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valgur/e647354c600a43b8aebd81578821c7f7 to your computer and use it in GitHub Desktop.
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
# 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