[nycphp-talk] Zip Code Stuff
jellicle at gmail.com
Mon Jan 22 10:09:23 EST 2007
On Monday 22 January 2007 9:39 am, Urb LeJeune wrote:
> >There are 8 Zip codes withing a 5 miles radius of 05701
> >They are:
> >05251 Dorset, VT 0.85 miles
> >05701 Rutland, VT 0.00 miles
> >05702 Rutland, VT 0.00 miles
> >05736 Center Rutland, VT 2.59 miles
> >05744 Florence, VT 3.57 miles
> >05759 North Clarendon, VT 2.13 miles
> >05765 Proctor, VT 4.57 miles
> >05777 West Rutland, VT 3.57 miles
> >Dorset is a lot more than 0.85 miles. It's really about 25 street
> > miles.
> The program uses longevity and latitude from a commercial zip
> code database. It calculates the great circle distance between two sets
> of coordinates. The supplied coordinates could be wrong for Dorset or
> Rutland. Do the airline distances to the other locations seem
You almost certainly want to use the Haversine formula for this task
(calculating distances to points that are quite close on a sphere).
The basic Great Circle formula gives *incorrect* results for points that are
very close to each other. I.E., the zip code 05702 is NOT actually on top
of 05701, and I expect that your database of zip code centroids is fine,
however, at some point roundoff error is killing you. That is,
arccos(1) = 0 //true!
arccos(.999999999) = 0 //true for computers, not true for mathematicians
So zip 05702 is too close to zip 05701, and its arccos is getting rounded to
zero, which makes the distance calculated be zero, which is untrue.
Use one of the other formulas on that Wikipedia page.
More information about the talk