Skip to content

Instantly share code, notes, and snippets.

@non117
Created February 10, 2014 16:12
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 non117/8918688 to your computer and use it in GitHub Desktop.
Save non117/8918688 to your computer and use it in GitHub Desktop.
緯度経度 to メートル
from math import sqrt, sin, cos, pi
def distance(lat1, lon1, lat2, lon2):
"""
Hubeny method
args : latitude1, longitude1, latitude2, longitude2 (degree)
return : m
"""
deg2rad = lambda deg: deg * (2 * pi) / 360
x1, y1, x2, y2 = map(deg2rad, (lon1, lat1, lon2, lat2))
a = 6378137.000
e2 = 0.00669438002301188
my = (y1 + y2) / 2
w = sqrt(1 - e2 * sin(my)**2)
n = a / w
m = 6335439.32708317 / w**3
dx, dy = x1 - x2, y1 - y2
m1, m2 = dy * m, dx * n * cos(my)
d = sqrt(m1**2 + m2**2)
return d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment