Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Spheroidal long-lat distance calculation
Message
De
16/02/2007 10:11:43
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
15/02/2007 17:00:37
Mike Yearwood
Toronto, Ontario, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01196313
Message ID:
01196545
Vues:
17
>Hey all
>
>I've been trying to use the third formula on this page:
>
>http://en.wikipedia.org/wiki/Great-circle_distance
>
>The formula is unnamed, but is indicated as being the most accurate.
>
>My trig is pretty rusty, and I don't think I ever did it on a sphere. :)
>
>I'm plugging in the sample lat-long for BNA and LAX and I'm not getting the same results.
>
>I've converted everything to radians. They name a formula in the "worked example" but that name is not referenced elsewhere on the page, so I'm not even sure which formula they're trying to demonstrate.
>
>Can anyone show me what I'm missing?
>
>Thanks!
>
>
CLEAR
>SET DECIMALS TO 5
>
>m.lat1 = 36.12
>m.long1 = -86.67
>?"lat1",m.lat1,"long1",m.long1
>
>m.lat2 = 33.94
>m.long2 = -118.40
>?"lat2",m.lat2,"long2",m.long2
>
>m.DeltaSigma = MyDistance(m.lat1,m.long1,m.lat2,m.long2)
>
>?"delta-sigma",m.DeltaSigma
>
>m.Dist = m.DeltaSigma * 6372.795
>?m.Dist
>RETURN
>
>
>FUNCTION myDistance
>LPARAMETERS m.lat1, m.long1, m.lat2, m.long2
>LOCAL m.rlat1, m.rlong1, m.rlat2, m.rlong2
>
>m.rlat1 = DTOR(m.lat1)
>m.rlong1 = DTOR(m.long1)
>?"rlat1",m.rlat1,"rlong1",m.rlong1
>
>m.rlat2 = DTOR(m.lat2)
>m.rlong2 = DTOR(m.long2)
>?"rlat2",m.rlat2,"rlong2",m.rlong2
>
>m.DeltaLong = m.long2 - m.long1
>
>m.rDeltaLong = DTOR(m.DeltaLong)
>
>m.DeltaSigma = ;
>  atan( ;
>    SQRT(;
>      (COS(m.rlat2) * SIN(m.rDeltaLong))^2 + ;
>      (COS(m.rlat1) * SIN(m.rlat2) - SIN(m.rlat1) * COS(m.rlat2) * COS(m.rDeltaLong))^2;
>    ) ;
>    / ;
>      (SIN(m.rlat1) * SIN(m.rlat2)) + (COS(m.rlat1) * COS(m.rlat2) * COS(m.rDeltaLong)) ;
>  )
>
>return m.DeltaSigma
Mike,
This one looks simplier (from Fox2x samples):
? GeoDist(36.12,-86.67,33.94,-118.40)

Function GeoDist
parameters lat1,lng1,lat2,lng2
*
* Degrees to radian
*
lat1 = Dtor(lat1)
lat2 = Dtor(lat2)
lng1 = Dtor(lng1)
lng2 = Dtor(lng2)

return 6372.795 * acos(sin(lat1) * sin(lat2) +;
    cos(lat1) * cos(lat2) * cos(lng2 - lng1)) && kilometers
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform