Lines 41
Keywords
GIS (7) GPS distance (1)
Permissions
Owner: Stou S.
Viewable by Everyone
Editable by All Siafoo Users

Earth distance formula 0

 In Brief A set of functions for performing various geographic calculations. Require SciPy
 Language Python
# 's
1import numpy
2import math
3from scipy import *
4
7
8def mercator_coords(geo_pt, center):
9 '''
10 Projects the given coordinates using Mercator projection
11 with respect to `center`.
12 '''
13
14 x = geo_pt[0: , :1] - center[0]
15 y = arctanh(numpy.sin(geo_pt[0 : , 1:]*(numpy.pi/360)))
16
17 return hstack((x,y))
18
19def distance_in_km(lon1, lat1, lon2, lat2):
20 '''
21 Given a set of geo coordinates (in degrees) it will return the distance in km
22 '''
23
25 lon1 = lon1*2*numpy.pi/360
26 lat1 = lat1*2*numpy.pi/360
27 lon2 = lon2*2*numpy.pi/360
28 lat2 = lat2*2*numpy.pi/360
29
31
32 #haversine formula - angles in radians
33 deltaLon = numpy.abs(lon1-lon2)
34 deltaLat = numpy.abs(lat1-lat2)
35
36 dOverR = haver_sin(deltaLat) + numpy.cos(lat1)*numpy.cos(lat2)*haver_sin(deltaLon)
37
38 return R * arc_haver_sin(dOverR)
39
41 '''
43 '''
44
47
48 return numpy.sqrt(top/bottom)
49
50def haver_sin(x):
51 return numpy.sin(x/2) ** 2
52
53def arc_haver_sin(x):
54 return 2*numpy.arcsin(numpy.sqrt(x))

A set of functions for performing various geographic calculations. Require SciPy