get_geoid_table.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python3
  2. """Simple program to exact 5x5 geoid separations in EGM2008.
  3. Use the GeoidEval program from:
  4. https://geographiclib.sourceforge.io
  5. Maybe someday use their python?
  6. from GeoidEval for use in geoidc
  7. """
  8. import sys
  9. import subprocess
  10. for lat in range(-90, 91, 5):
  11. if -90 != lat:
  12. sys.stdout.write("},")
  13. sys.stdout.write("\n /* %d */\n { " % lat)
  14. cnt = 0
  15. for lon in range(-180, 181, 5):
  16. ge = subprocess.Popen(["GeoidEval",
  17. "-n", "egm2008-1"],
  18. stdin=subprocess.PIPE,
  19. stdout=subprocess.PIPE,
  20. stderr=subprocess.PIPE,
  21. bufsize=0)
  22. out, err = ge.communicate(b"%d %d\n" % (lat, lon))
  23. # round to even cm
  24. val = round(float(out) * 100)
  25. sys.stdout.write("%5d" % val)
  26. cnt += 1
  27. if 0 == (cnt % 10):
  28. sys.stdout.write(",\n ")
  29. elif 73 != cnt:
  30. sys.stdout.write(", ")
  31. sys.stdout.write("}\n};\n")