Re:A fast, offline reverse geocoder in Python
by shawn-butler on Saturday March 28, 2015 @03:32PM
(#9282477)
I can recommend the excellent Geographic lib::Geodesic for this having used it in the past.
http://geographiclib.sourceforge.net
There is a python implementation available as well. http://pypi.python.org/pypi/geographiclib
Re:A fast, offline reverse geocoder in Python
by thampiman on Monday March 30, 2015 @04:51AM
(#9288358)
Thanks!
Re:A fast, offline reverse geocoder in Python
by thampiman on Monday March 30, 2015 @01:06PM
(#9290882)
I've fixed this by converting the geodetic coordinates to ECEF. See v1.2 release notes here: https://github.com/thampiman/reverse-geocoder
Re:A fast, offline reverse geocoder in Python
by thampiman on Saturday March 28, 2015 @01:05PM
(#9282018)
Good point. I would need to use this distance function instead: http://www.movable-type.co.uk/scripts/latlong.html
On it!
Re:A fast, offline reverse geocoder in Python
by corford on Saturday March 28, 2015 @01:31PM
(#9282102)
Here's a python function we use to calculate haversine distances:
import math
from collections import namedtuple
def haversine_distance(origin, destination):
""" Haversine formula to calculate the distance between two lat/long points on a sphere """
radius = 6371 # FAA approved globe radius in km
dlat = math.radians(destination.lat-origin.lat)
dlon = math.radians(destination.lng-origin.lng)
a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(origin.lat)) \
* math.cos(math.radians(destination.lat)) * math.sin(dlon/2) * math.sin(dlon/2)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
d = radius * c
# Return distance in km
return int(math.floor(d))
LatLng = namedtuple('LatLng', 'lat, lng')
origin = LatLng(51.507222, -0.1275) # London
destination = LatLng(37.966667, 23.716667) # Athens
print "Distance (km): %d" % haversine_distance(origin, destination)
First, longitude wraps from -180 to +180 at antimeridian, meaning distance calculations will fail there; second, and I'd say more importantly, one degree longitude length in meters differs a lot depending on latitude; meaning this library will be heavily biased towards longitudal neighbors when using it for locations far from equator.