LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (April 1997, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 9 Apr 1997 08:21:45 +0200
Reply-To:   Willem Dekker <Willem@RIVO.DLO.NL>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   Willem Dekker <Willem@RIVO.DLO.NL>
Subject:   Re: Mapping Questions
In-Reply-To:   <3342344A.43FF@ga.unc.edu>
Content-Type:   text/plain; charset="us-ascii"

Yesterday Keith Brown asked:

>Hi all, > I've got a couple of questions relating to mapping in SAS, and >hope someone out there can help. > > First, does anyone have a good formula for calculating distance >between two points? Currently, I'm using the following, but would >appreciate a formula that has a little more solid cartographical >foundation: > >longlen=69*(cos(lat*arcos(-1)/180)); >y1len=69*(cos(lat1*arcos(-1)/180)); >distx=69*(lat1-lat); >disty=(long1-long)*((longlen+y1len)/2); >distance=round(sqrt(sum(distx**2,disty**2))); >

I am using the macro down below. It calculates the length of the shortest arc through both positions. The main shortcoming is that I assume the earth is a perfect sphere, which it is not. Therefore, there might be better ones.

%MACRO distance(lat1, lon1, lat2, lon2);

%* calculates distance between two locations on earth; %* depends crucially on the accurcy of the calculations!;

%* input: latitude and longitude in radians; %* output: distance in meters, as a data step expression; %* version: 26 June 1996, Willem Dekker;

%Let Mile=1853.245; %* Nautical mile in meters; %Let DegRad=180/3.141592653589793238; %* Degrees per Radian; %LET MeterRad=60*&Mile*&DegRad; %* meters per radian;

(&MeterRad * 2 * arsin(sqrt(2 - 2 * cos(&lat1) *cos(&lat2) * cos(&lon1 - &lon2) - 2 * sin(&lat1) * sin(&lat2) ) / 2)); %mend;

Willem Dekker | e-mail: willem@rivo.dlo.nl Netherlands Institute for| s-mail: RIVO, P.O. Box 68, 1970 AB IJmuiden, NL Fisheries Research | phone : +31 255 564 712 =========================| fax : +31 255 564 644


Back to: Top of message | Previous page | Main SAS-L page