This is fairly easy to do.
1. you need a list of zip codes w/ their gps coordinates. Get any good
maping program and dump them out to an ascii file and load them into a table
in your database.
Finding the distance between 2 points is just basic trig distance = Xsquared
+ Ysquared = Zsquared.
Here is the trick, 1 knotical mile approximatly equals 1 minute.
But lets say you want to do it the other way and find all of the zipcodes in
a radius of a given zipcode. Well you don't want to have to compute the
distances between every zipcode. There are like 70,000 in the US.
Now we know that 1 knot ~= 1 minute.
I think w/o looking at my code 1.2 miles = 1 knotical mile.
Now lets say I can fudge it a bit more and instead of a radius, use a
square.
Bingo - add and subtract the 1/2 the number of knots you want to the
longitude and latitude of your starting point. Now you have the corners of
your square and you can do a select from you zipcode table using long
between .... and lat between .....
At this point if the approximation is not good enough, you could go through
your approximation result set and compute the distance every point.
Here is the code I have written in R:base. You can use this logic and write
a taf to do the same thing.
Have fun,
Troy
-----Original Message-----
From: Nicholas Froome [mailto:[EMAIL PROTECTED]
Sent: Sunday, March 09, 2003 5:11 PM
To: [EMAIL PROTECTED]
Subject: Witango-Talk: Calculating distance from Post/Zip codes (2)
I asked:
>Has anyone written a TAF to calculate distances between two UK postcodes
and, if so, would they like to share it?
As it seems no-one has, does anyone have a TAF to calculate distance from
Northings and Eastings? I can look these up from a table of Postcodes
There are ASP and PHP apps around to do this job, but I use neither and
don't particularly want to bolt one of these apps on - or try and revesrse
engineer one
How are you all doing distance calculations?
________________________________________________________________________
TO UNSUBSCRIBE: send a plain text/US ASCII email to [EMAIL PROTECTED]
with unsubscribe witango-talk in the message body
________________________________________________________________________
TO UNSUBSCRIBE: send a plain text/US ASCII email to [EMAIL PROTECTED]
with unsubscribe witango-talk in the message body*( zipin30.cmd
This returns a list of all zipcodes in approximatly 30 miles of
the given zipcode.
This uses a square approximation calculation method.
Written by: Troy Sosamon EAP 3/16/01
)
set var vvzip TEXT -- passed in - zipcode to find
set var vvmiles int -- passed in - miles to use
set var vvzips text=null -- passed back - sub select
if vvzip is null then
write 'var vvzip required = 12345' white on red
goto end_z30
endif
if vvmiles is null then
write 'var vvmiles required = 30' white on red
goto end_z30
endif
set var vvmin_offset INT = ((INT(.vvmiles / 1.15)) * 10000)
set var vvlong int = 0
set var vvlat int = 0
select longitude,latitude into vvlong, vvlat from zipcodes +
where zipcode = .vvzip
if sqlcode = 100 then
-- bad zipcode
GOTO end_z30
endif
set var vvlong_top = (.vvlong + .vvmin_offset)
set var vvlong_bot = (.vvlong - .vvmin_offset)
set var vvlat_top = (.vvlat + .vvmin_offset)
set var vvlat_bot = (.vvlat - .vvmin_offset)
set var vvzips = (
'SELECT zipcode FROM zipcodes where longitude between' & +
(ctxt(.vvlong_bot)) & 'and' & (ctxt(.vvlong_top)) & +
'and latitude between' & (ctxt(.vvlat_bot)) & 'and' & (ctxt(.vvlat_top)))
label end_z30
cle var vvlong%, vvlat%, vvmin_offset
return