Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MATH - getting rows within a radius
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01219992
Message ID:
01220765
Vues:
21
The radius of the earth is assumed to be 3963.189 miles. That makes the circumference of the earth 24,901.4297 miles using the equation of Radius * 2 * PI (3.14159). If you divide the circumference by 360 (number of degrees in a circle) you will get 69.1706 linear miles per latitude or longitude. However, the longitude value changes considerably as one moves from the equator toward the polar caps.

The correct calculation needs to make use of spherical geometry and apply what is popularly known as the great-circle distance ( http://en.wikipedia.org/wiki/Great_circle_distance ) formula. The first step is to convert the latitude / longitude coordinates from degrees to radians via the DTOR() function. The rest of the equation makes uses of arc cosines, sines and cosines as follows:


nLat1 = DTOR( m.nLat1 )
nLon1 = DTOR( m.nLon1 )
nLat2 = DTOR( m.nLat2 )
nLon2 = DTOR( m.nLon2 )

nRetVal = 3693.189 * ACOS( SIN( m.nLat1 ) * SIN( m.nLat2 ) + COS( m.nLat1 ) * ;
COS( m.nLat2 ) * COS( m.nLon2 - m.nLon1 ) )

Here is a code snippet of how I use this in an actual application (notice that .nLat1 and .nLon1 are pre-established just use the degrees to radians function and you are set):
 FUNCTION Distance( tnLat2, tnLon2 )
    LOCAL nRetVal AS Number 
    WITH This
     *-- Convert degrees to radians
     .nLat2 = DTOR( m.tnLat2 )
     .nLon2 = DTOR( m.tnLon2 )
     
      *-- Radius of the earth is 3,963.189 miles 
      nRetVal = 3963.189 * ACOS( SIN( .nLat1 ) * SIN( .nLat2 ) + COS( .nLat1 ) * COS( .nLat2 ) * COS( .nLon2 - .nLon1 ) )
    ENDWITH
    
    RETURN m.nRetVal
  ENDFUNC   
>I have a table of warrants with latitude and longitude, and I would like to be able to select all warrants within a given radius. I know I've seen this discussed before. Any of you math professors got a clue?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform