Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Latitude/Longitude calculations
Message
From
27/06/2001 00:33:58
Barry Leboeuf
Matrix Computer Services
Texas, United States
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00523348
Message ID:
00523983
Views:
7
>I'm trying to use Latitude/Longitude calculations in a application. Does anyone have a formula for calculating the distance between two points given in lat/long?
Here is a "standard" fortran routine that I converted to VFP. There are also this set of defines that are required by this routing. hope this helps.
* Math conversion Factors
#DEFINE CMT2MI .0006214
#DEFINE CMI2KT .8684
#DEFINE CDG2RD 1.74532925199433E-2
#DEFINE REARTH 20925197.0
#DEFINE CFT2MT 0.3048
#DEFINE CMI2MT 1609.344
#DEFINE POLARRADIUS 6356912.0
#DEFINE EARTHRADIUS 6371220.0
#DEFINE MAPLAT 54.00
#DEFINE MAPLNG -9.00
#DEFINE LATDEGTOMETERS 110949.0447 && (POLARRADIUS*(2*pi())/360.0)
#DEFINE METERSTOLATDEG 0.0003558224763751000 && 360.0 /POLARRADIUS*(2*pi())
#DEFINE KT2MT 1E3

LOCAL LATRADA,LONGRADA,LATRADB,LONGRADB,DACOS_ARG,ARC_ANGLE
*
*********************************************************************
*--------------------------------------------------------------------
*     MODULE:   CDIST
* 
*     ABSTRACT:  *
*      The purpose of this function is to compute the distance between
*      two points on the Earths surface given only the latitude and
*      longitude of both points
*
*--------------------------------------------------------------------
*     LANGUAGE:                  FORTRAN 77
* 
*     TARGET PROCESSOR:          
* 
*     METHOD OF ACTIVATION:      distance = CDIST(lata,longa,latb,longb)
*
*     INPUTS:
*        REAL*4  LATA          ! Latitude of the first point  (DEG.HUN_DEG)
*        REAL*4  LONGA         ! Longitude of the first point (DEG.HUN_DEG)
*        REAL*4  LATB          ! Latitude of the second point (DEG.HUN_DEG)
*        REAL*4  LONGB         ! Longitude of the second point (DEG.HUN_DEG)
*
*     OUTPUTS:
*        REAL*4  CDIST         ! Distance in METERS, returned through
*                              !    function call name
*
*    GLOBAL DATA SETS REFERENCED:   
*        BCONST.PRM    ! Math Constants
*
*     CALLED SUBROUTINES:              NONE.
*
*     ERROR PROCESSING:                NONE.
*
*     ASSUMPTIONS/RESTRICTIONS:        NONE.
*--------------------------------------------------------------------------
*     REVISION HISTORY:
*     REVISION  DATE     AUTHOR  COMMENT
*       0.00    07/21/88    SS    SOURCE CREATION
*
*********************************************************************
*
*                    *DATA DECLARATIONS*
* 
* Math Constants
*
*
* LOCAL_BEGIN
*
*     REAL*4  LATA          
* Latitude of the first point
*     REAL*4  LONGA         
* Longitude of the first point
*     REAL*4  LATB          
* Latitude of the second point
*     REAL*4  LONGB         
* Longitude of the second point
*
*     REAL*8  LATRADA       
* Latitude of the first point - RADIANS
*     REAL*8  LONGRADA      
* Longitude of the first point - RADIANS
*     REAL*8  LATRADB       
* Latitude of the second point - RADIANS
*     REAL*8  LONGRADB      
* Longitude of the second point - RADIANS
*
*     REAL*8  ARC_ANGLE,DACOS_ARG
* Angle of an arc, radians
*
 *     REAL*8  D1ARG,D2ARG,D3ARG,D4ARG,D5ARG,DCOSARG
*
* LOCAL_END
*
*.... Latitude and Longitude are input in
*.... Degrees.decimal_degrees
*
*.... Result is returned in METERS
*
*
*.... Latitude and Longitude are input in
*.... Degrees.decimal_degrees
*
*.... Result is returned in METERS
*
*.... This function uses the GREAT CIRCLE NAVIGATION formulas to
*.... compute the distance between two points on the earths surface.
*
*.... Take a sphere.  Intersect it through the center with a plane and
*.... a great circle is produced.  An arc on a great circle is measured
*.... by the angle it subtends.  A spherical triangle is made up of 
*.... three arcs of great circles.
*
*.... NOTE:  Great-Circle navigation is based on the spherical triangle
*
*.... The distance we calculate will be in nautical miles.  The nautical
*.... mile is defined as:  the arc length subtended on a circle of 
*.... diameter 7926.68 miles (earth) by a central angle of 1 (one minute)
*.... A nautical mile is equal to:
*....      (0.5 * (7926.68)(5280)* pie) / (60 * 180) = 6080.27 feet
*
*.... Now, we start the computations:
*.... First, convert the Degrees.Decimal_degress to Radians
*
      LATRADA = this.curlat * CDG2RD    
      LONGRADA = this.curlon * CDG2RD
      LATRADB = this.nextlat * CDG2RD    
      LONGRADB = this.nextlon * CDG2RD

*
*.... Now we compute the angle (in radians) of the arc
*
      DACOS_ARG = ( (SIN(LATRADA) * SIN(LATRADB)) +;
                     ((COS(LATRADA) * COS(LATRADB)) *;
                      (COS(LONGRADA - LONGRADB))))
      ARC_ANGLE =ACOS(DACOS_ARG)
      this.DISTTONEXTWP = ((REARTH * ARC_ANGLE) * CFT2MT)
Previous
Reply
Map
View

Click here to load this message in the networking platform