Discussion:
Lat/Lon Origination Coordinates, Bearing,
(too old to reply)
Fehd, Ronald J. (CDC/CCHIS/NCPHI)
2007-10-18 15:38:21 UTC
Permalink
Does anyone have a formula for calculating the destination
lat/lon based on an origination lat/lon, bearing and distance?
keyword: zipcode zip code latitude longitude

flat, round, hole in middle: it's been invented:

http://www.sascommunity.org/wiki/Calculating_Distance_Between_Two_Zip_Co
des

see also:

PROC SQL; describe table sashelp.zipcode;
quit;

see also:

http://www.sascommunity.org/wiki/Returning_Zip_Codes_in_a_Specified_Radi
us

Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov
Samuel Croker
2007-10-18 18:40:40 UTC
Permalink
Hi Aaron

Fun stuff! I think that the haversine formula will do the job for you
with some algebraic manipulation to do the bearing/distance version.
Check out http://www.movable-type.co.uk/scripts/latlong.html.
If you need to be really precise you will have to take into account
the oblateness of the earth, I cannot remember this adjustment at the
moment but I did encounter it in my past somewhere so it is out there.
The adjustment is slight however and for most purposes the speherical
assumption is ok.

Cheers,

Sam
Does anyone have a formula for calculating the destination lat/lon
based on an origination lat/lon, bearing and distance?
I know that mathworld.Wolfram.com has a lot of formulas in their
searchable database of formulas relating to latitude and longitude and
distance.
I also heard that something called google might be good for searching
for things.
--
Paige Miller
paige\dot\miller \at\ kodak\dot\com
--
Samuel T. Croker
Lexington, SC & Bethesda, MD
Duell, Bob
2007-10-18 19:31:44 UTC
Permalink
I have a sample SAS program to calculate the distance and bearing
between to points. There are two completely different distance formulas
(Law of Cosines and Haversine); also, I included several definitions for
the Earth Radius constant.

I derived this after reading a whole lot of web sites, little of which I
truly understand. My "production" code distills all of this into a
single formula with lots of imbedded function calls. It works well for
me, and I hope it does for you.

I'd be happy to share this on the Wiki site, but I haven't figured out
how to do that. If someone wants to post it there, I'm fine with that;
no credit necessary.

There's the code:

/* These examples demonstrate how to calculate the distance */
/* in miles between two geographic coordinate pairs. */
/* Note, the examples expect the data starts as "degrees". */
/* and converts the coordinates to radians. If your data is */
/* already in radians, modify accordingly. */

data SAS_TABLE;

if _n_ = 1 then do;
/* Define Pi as a constant */
Pi = constant('pi'); /* Use the SAS function to improve precision
*/

/* Define Earth radius as a constant in miles */
* 1 kilometer = 0.6213712 mile;
* P=Polar Radius = 6356.9 km (3949.99453 miles);
* E=Equatorial radius = 6378.5137 km (3963.42477 miles);
* M=Mean volumetric radius = 6371.01 km (3958.76208 miles);
* Q=Quadradic mean radius = 6372.795478 km (3959.87152 miles);
* Q=SQRT((3E**2 + P**2)/4);
* GIS FAQ = 6367 km (3956.2704 miles);

REarth = 3956.2704;
end;
retain Pi REarth;

/* First location. */
deg_lon1 = -81.2238;
deg_lat1 = 35.25927;

/* Second location. */
deg_lon2 = -81.1492;
deg_lat2 = 35.22143;

/* First convert degrees to radians, if necessary */
rad_lon1 = deg_lon1 * pi / 180;
rad_lat1 = deg_lat1 * pi / 180;
rad_lon2 = deg_lon2 * pi / 180;
rad_lat2 = deg_lat2 * pi / 180;

/* Law of Cosines for Spherical Trigonometry (uses radius) */
dist_miles1 = REarth * ARCOS( ( COS(rad_lat1) * COS(rad_lat2) *
COS(rad_lon1-rad_lon2) )
+ ( SIN(rad_lat1) * SIN(rad_lat2) )
);
/* Haversine Formula (uses diameter) */
A = sin( (rad_lat2 - rad_lat1)/2.0 )**2
+ ( cos(rad_lat1)
* cos(rad_lat2)
* sin((rad_lon2 - rad_lon1)/2.0)**2
);
dist_miles2 = (REarth * 2) * atan2(sqrt(A),sqrt(1-A));

/* Calculate bearing */
rad_Bearing = mod(atan2(sin(rad_lon1-rad_lon2)*cos(rad_lat2),

cos(rad_lat1)*sin(rad_lat2)-sin(rad_lat1)*cos(rad_lat2)*cos(rad_lon1-rad
_lon2)), 2*Pi);

/* Convert bearing to degrees and create display variable as
degrees-minutes-seconds */
deg_Bearing = rad_Bearing * 180 / Pi;

Degrees = Int(abs(deg_Bearing));
Minutes = (abs(deg_Bearing) - Degrees) * 60;
Seconds = round((Minutes - Int(Minutes)) * 60);
Bearing_txt = put(degrees,3.) || 'B0'x || put(minutes,2.) || "'" ||
put(seconds,2.) || '"';
run;

-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-***@LISTSERV.UGA.EDU] On Behalf Of
***@GMAIL.COM
Sent: Thursday, October 18, 2007 7:08 AM
To: SAS-***@LISTSERV.UGA.EDU
Subject: Lat/Lon Origination Coordinates, Bearing,
Distance....Destination Coordinates?

Does anyone have a formula for calculating the destination lat/lon
based on an origination lat/lon, bearing and distance?

Much Thanks,
Aaron

Loading...