Live data from Hacker News

A fast, offline reverse geocoder in Python

github.com

21–30 of 46 posts

Re: A fast, offline reverse geocoder in Python

#21

If you're interested in making both forward and reverse geocoding better, please consider paying attention to a project I started and help maintain called OpenAddresses: http://openaddresses.io The goal is to collect address datasets so that forward and reverse geocoding is an easier problem to solve. A contributor wrote an excellent overview of the project the other day: https://medium.com/colemanm/creating-an-open-…

Very cool project. Out of curiosity, how do you test the validity of the addresses?

All of the addresses come from "authoritative" datasets (i.e. from local or state governments) so we're assuming them to be correct.

Re: A fast, offline reverse geocoder in Python

#23
Kudos for a very well done README (and it's not just cribbed from the original project, it explains the new stuff very well and tells what the project is, and gives credit back). So many projects neglect the README.

One question - is it OK to put an MIT license on something that is based on LGPL code? I don't know enough about how the LGPL works (I do know it is less "infective" than plain GPL).

Well two questions: python2, or python3?

Re: A fast, offline reverse geocoder in Python

#24
post #23

Kudos for a very well done README (and it's not just cribbed from the original project, it explains the new stuff very well and tells what the project is, and gives credit back). So many projects neglect the README. One question - is it OK to put an MIT license on something that is based on LGPL code? I don't know enough about how the LGPL works (I do know it is less "infective" than plain GPL). Well two questions: p…

Thanks for that comment!

Good question regarding the license. I'm not too sure about that. I'd appreciate it if someone could shed some light on it.

Regarding the version, I've only tested it on python2. I should add that in the README. Thanks!

Re: A fast, offline reverse geocoder in Python

#25

If you're interested in making both forward and reverse geocoding better, please consider paying attention to a project I started and help maintain called OpenAddresses: http://openaddresses.io The goal is to collect address datasets so that forward and reverse geocoding is an easier problem to solve. A contributor wrote an excellent overview of the project the other day: https://medium.com/colemanm/creating-an-open-…

It's a nice overview but it glosses over the fact that while the OA database is governed by a CC0 license, the individual address collections in the database are still governed by their own licenses which can be (much) more restrictive. The fact that you can download the data doesn't mean you can use it the way you want. The OA web site hints at this but doesn't address (ah-hah) that underlying problem. That doesn't mean that OA is not valuable - quite the contrary - but I think the fact that it's presented as one big free and open dataset can be misleading.

Re: A fast, offline reverse geocoder in Python

#26
post #23

Kudos for a very well done README (and it's not just cribbed from the original project, it explains the new stuff very well and tells what the project is, and gives credit back). So many projects neglect the README. One question - is it OK to put an MIT license on something that is based on LGPL code? I don't know enough about how the LGPL works (I do know it is less "infective" than plain GPL). Well two questions: p…

Thanks for that comment! Good question regarding the license. I'm not too sure about that. I'd appreciate it if someone could shed some light on it. Regarding the version, I've only tested it on python2. I should add that in the README. Thanks!

As of now, for Python 3 it does not work, but it seams that fixes are not hard: https://github.com/thampiman/reverse-geocoder/issues/2

Re: A fast, offline reverse geocoder in Python

#27
You can't really use KD trees with lat/lon coordinates, at least you can't use euclidean distance there for nearest neighbor search.

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.

Re: A fast, offline reverse geocoder in Python

#28
post #27

You can't really use KD trees with lat/lon coordinates, at least you can't use euclidean distance there for nearest neighbor search. 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 neighb…

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

#30
post #27

You can't really use KD trees with lat/lon coordinates, at least you can't use euclidean distance there for nearest neighbor search. 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 neighb…

Good point. I would need to use this distance function instead: http://www.movable-type.co.uk/scripts/latlong.html On it!

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)
Post reply on HN