Skip to content

Instantly share code, notes, and snippets.

@StreakyCobra
Created May 22, 2017 14:16
Show Gist options
  • Select an option

  • Save StreakyCobra/4971c829a6ce048f34297b84c47417f8 to your computer and use it in GitHub Desktop.

Select an option

Save StreakyCobra/4971c829a6ce048f34297b84c47417f8 to your computer and use it in GitHub Desktop.
Convert HGT data to XYZ points.
#!/usr/bin/env python
"""Convert HGT data to XYZ points."""
import sys
from functools import partial
def main(inputname, outputname):
"""Entry point of the program."""
alts = []
with open(inputname, 'rb') as f:
for p, chunk in enumerate(iter(partial(f.read, 2), '')):
if len(chunk) == 0:
break
alt = chunk[0]
alt <<= 8
alt |= chunk[1]
x, y = divmod(p, 3601)
x *= 30
y *= 30
alts.append((x, y, alt))
with open(outputname, 'w') as f:
for entry in alts:
print("{} {} {}".format(*entry), file=f)
if __name__ == '__main__':
if len(sys.argv) < 3:
print("Usage: {} INPUT OUTPUT".format(sys.argv[0]))
sys.exit(1)
INPUT = sys.argv[1]
OUTPUT = sys.argv[2]
main(INPUT, OUTPUT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment