/*-------------------------------------------------------------------* File........: latlon.i Version.....: 1.0 12/28/01 Description : Latitude Longitude Function Library Input Param : Output Param: Author......: Paul Keary - Coe Press Equipment. (586) 979-4400 Copyright...: FreeFramework 2001 - http://www.freeframework.org Created.....: 12/28/01 Notes.......: This library was created to be a 4gl replacement for S.E. Southwell's trig.i which requires external modules for the math functions. The sole purpose of the this program was to create a portable version across platforms It relies heavily on the maths.i library found on the PEG (written by Michael Carroll). GreatCircleDistance computes the distance between 2 coordinates, all my testing was done with NAD27 coords, all bets are off if using other coordinate systems. NOTE: FUNCTIONS USED IN THIS LIBRARY EXPECT TO GET LAT-LONG COORDS IN DEGREES NOT RADIANS. Adapted from File........: trig.i Version.....: .8 6/26/01 Description : Trigonometric function library Input Param : Output Param: Author......: S.E. Southwell - BravePoint, Inc. (770) 449-9696 Copyright...: FreeFramework 2001 - http://www.freeframework.org Created.....: 6/26/01 Notes.......: *--------------------------------------------------------------------*/ &SCOPED-DEFINE CONSTANT_PI 3.1415926536 &SCOPED-DEFINE CONSTANT_PerDeg 69.0346970272 &SCOPED-DEFINE Earth_Radius 3437.746770 {utils/maths.i} FUNCTION Deg2Rad RETURNS DECIMAL ( INPUT deg as DECIMAL): DEF VAR radians as DECIMAL no-undo. radians = deg * {&CONSTANT_PI} / 180. RETURN radians. END FUNCTION. FUNCTION GreatCircleDistance RETURNS DECIMAl ( input lon1 as decimal, input lat1 as decimal, input lon2 as decimal, input lat2 as decimal): def var myreturn as decimal no-undo. def var x as decimal no-undo. def var y as decimal no-undo. /* 120 = 60 * 2 */ myreturn = {&CONSTANT_PERDEG} * 2 * ASIN( SQRT( EXP( SIN((lat1 - lat2) / 2) ,2) + cos(lat1) * cos(lat2) * EXP( Sin((lon1 - lon2) / 2) ,2) )). return myreturn. end function. FUNCTION West RETURNS DECIMAL ( input lat1 as DECIMAL, input lon1 as DECIMAL, input distance as DECIMAL): define var myreturn as DECIMAL no-undo. myreturn = lon1 - (distance / (cos(deg2rad(lat1)) * {&CONSTANT_PERDEG})). IF myreturn < -180 THEN myreturn = myreturn + 360. IF myreturn > 180 THEN myreturn = myreturn - 360. RETURN myreturn. END FUNCTION. FUNCTION North RETURNS DECIMAL ( input lat1 as DECIMAL, input distance as DECIMAL): DEF VAR myreturn as DECIMAL NO-UNDO. myreturn = lat1 + (distance / {&CONSTANT_PERDEG}). IF myreturn > 90 THEN myreturn = 90 - (myreturn - 90). RETURN myreturn. end function. FUNCTION East RETURNS DECIMAL ( input lat1 as DECIMAL, input lon1 as DECIMAL, input distance as DECIMAL): DEF VAR myreturn as DECIMAL no-undo. myreturn = lon1 + (distance / (cos(deg2rad(lat1)) * {&CONSTANT_PERDEG})). IF myreturn < -180 THEN myreturn = myreturn + 360. IF myreturn > 180 THEN myreturn = myreturn - 360. RETURN myreturn. END FUNCTION. FUNCTION South RETURNS DECIMAL ( input lat1 as DECIMAL, input distance as DECIMAL): DEF VAR myreturn as DECIMAL no-undo. myreturn = lat1 - (distance / {&CONSTANT_PERDEG}). if myreturn < -90 then myreturn = -90 + (myreturn + 90). RETURN myreturn. END FUNCTION.