[Zope] searching by miles from __ zip code
Dennis Allison
allison@sumeru.stanford.EDU
Thu, 12 Jun 2003 09:29:34 -0700 (PDT)
You proably should use a spherical earth model to compute distances.
Database search with a "distance from" key is difficult and requires
specialized mechanisms. There is a significant literature if you really
need the general mechanism. Here we've assumed that you have a way of
generating a small list of candidates and want to rank them by geographic
distance. A way different problem.
On 12 Jun 2003, Dylan Reinhardt wrote:
> On Wed, 2003-06-11 at 20:06, Sean Kelley wrote:
> > Has anyone done something in python/zope to allow for searching by
> > number of miles from a zip code?
>
> I did something like this several years ago, but not in Python. It
> isn't difficult if you're OK being accurate to within a mile or two.
>
> First thing, you get a data set that gives the map coordinates for each
> post office. USGS maintains a massive set of data about landmarks that
> includes this data, though it's probably available elsewhere as well.
>
> Once you have this data, you close your eyes and assume that since
> there's a 1:1 relationship between zip codes and post offices, you now
> have a map point that's somewhat central for each zip. Then you swear
> to yourself never to subject this hypothesis to actual testing. :-)
>
> You could just calculate the hypotenuse of a right triangle to get the
> distance between two map points, but first you have to deal with a
> problem: there are a fixed number of feet per degree of longitude, but
> the number of feet per degree of latitude varies considerably,
> particularly once Alaska and Hawaii are factored in.
>
> You could pick an average land distance for each degree of latitude or
> calculate the latitude distance based on the average of the longitudes
> being compared. I wouldn't be surprised if you could find a table that
> gives these figures.
>
> I suppose you could even include calculations for the curvature of the
> Earth, but given that you're only going to be accurate to a couple miles
> anyway, it's not going to make much difference at most intervals.
>