License Public Domain
 Lines 41
##### Keywords
GIS (7) GPS distance (1)
##### Permissions
Owner: Stou S.
Viewable by Everyone
Editable by All Siafoo Users
Meet people who work on similar things as you – get help if you need it

# 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 5eq_rad     = 6378.137 #eq radius in km 6polar_rad  = 6356.752 #polar radius in km 7 8def mercator_coords(geo_pt, center): 9    '''10    Projects the given coordinates using Mercator projection11    with respect to `center`.12    '''1314    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))1819def distance_in_km(lon1, lat1, lon2, lat2):20   '''21   Given a set of geo coordinates (in degrees) it will return the distance in km22   '''2324   #convert to radians25   lon1 = lon1*2*numpy.pi/36026   lat1 = lat1*2*numpy.pi/36027   lon2 = lon2*2*numpy.pi/36028   lat2 = lat2*2*numpy.pi/3602930   R = earthRadius((lat1+lat2)/2) #km3132   #haversine formula - angles in radians33   deltaLon = numpy.abs(lon1-lon2)34   deltaLat = numpy.abs(lat1-lat2)3536   dOverR = haver_sin(deltaLat) + numpy.cos(lat1)*numpy.cos(lat2)*haver_sin(deltaLon)3738   return R * arc_haver_sin(dOverR)3940def earth_radius(lat):41   '''42   Given a latitude in radias returns earth radius in km43   '''4445   top = (eq_rad**2 * numpy.cos(lat))**2 + (polar_rad**2 * numpy.sin(lat))**246   bottom = (eq_rad * numpy.cos(lat))**2 + (polar_rad * numpy.sin(lat))**247   48   return numpy.sqrt(top/bottom)4950def haver_sin(x):51   return numpy.sin(x/2) ** 25253def arc_haver_sin(x):54   return 2*numpy.arcsin(numpy.sqrt(x))`

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

## Comments

over 12 years ago (15 Mar 2008 at 03:02 PM) by David Isaacson
lol... I'm pretty sure I'm the one that wrote these originally.
over 12 years ago (20 Mar 2008 at 05:42 PM) by Stou S.
You for sure wrote some of them, come to think of it. I'll give you credit ;-)
over 12 years ago (27 Mar 2008 at 01:44 PM) by David Isaacson
Yeah, you can tell that the first one was you due to the extensive underbar use in the variable names :)
over 12 years ago (14 May 2008 at 10:47 AM) by Stou S.
Hey that's what pylint tells me to do.