comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: how to calculate distance from pairs of latitude/longitude measurements?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: how to calculate distance from pairs of latitude/longitude measurements? [message #65584] Thu, 12 March 2009 07:20
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On Mar 12, 8:02 am, mankoff <mank...@gmail.com> wrote:
> On Mar 11, 4:33 pm, llo <bernat.puigdomen...@gmail.com> wrote:
>
>
>
>> I am working on a project where I will be receiving measurements from
>> the Global
>> Positioning System, presumably latitude and longitude measurements,
>> and I will
>> need to calculate the distances between the measurement points. The
>> measurements
>> will all be taken over a region of only a few miles so I guess I could
>> assume
>> the earth is flat over this region and just calculate the straight
>> line
>> distance.
>
>> But I was wondering if anyone could help me with a more mathematically
>> rigorous method for calculating distance from pairs of latitude/
>> longitude
>> measurements?
>
>> thanks,
>
>> llo
>
> As mentioned below map_2points works. I've found distance_sphere (in
> the ICG library) to be handy because it works with vectors.
>
>    -k.

...or SPHDIST in the Astronomy User's Library.

-Jeremy.
Re: how to calculate distance from pairs of latitude/longitude measurements? [message #65590 is a reply to message #65584] Thu, 12 March 2009 05:02 Go to previous message
mankoff is currently offline  mankoff
Messages: 131
Registered: March 2004
Senior Member
On Mar 11, 4:33 pm, llo <bernat.puigdomen...@gmail.com> wrote:
> I am working on a project where I will be receiving measurements from
> the Global
> Positioning System, presumably latitude and longitude measurements,
> and I will
> need to calculate the distances between the measurement points. The
> measurements
> will all be taken over a region of only a few miles so I guess I could
> assume
> the earth is flat over this region and just calculate the straight
> line
> distance.
>
> But I was wondering if anyone could help me with a more mathematically
> rigorous method for calculating distance from pairs of latitude/
> longitude
> measurements?
>
> thanks,
>
> llo

As mentioned below map_2points works. I've found distance_sphere (in
the ICG library) to be handy because it works with vectors.

-k.
Re: how to calculate distance from pairs of latitude/longitude measurements? [message #65604 is a reply to message #65590] Wed, 11 March 2009 14:12 Go to previous message
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
I wrote this small program:

FUNCTION LATLON_DISTANCE, lat1, lon1, lat2, lon2, DEG=deg

IF KEYWORD_SET(deg) THEN BEGIN
lat1=lat1*(!PI/180.)
lon1=lon1*(!PI/180.)
lat2=lat2*(!PI/180.)
lon2=lon2*(!PI/180.)
ENDIF

R=6356.7523 ;; polar radius [km]

a=R*(!PI/2.-lat2)
b=R*(!PI/2.-lat1)

gamma=lon1-lon2

angle=COS(b/R)*COS(a/R)+SIN(b/R)*SIN(a/R)*COS(gamma)
distance=ACOS(angle)*R

RETURN, distance

END

The result is the same as MAP_2POINTS.
I'll use MAP_2POINTS anyway,

thanks
Re: how to calculate distance from pairs of latitude/longitude measurements? [message #65606 is a reply to message #65604] Wed, 11 March 2009 13:44 Go to previous message
KRDean is currently offline  KRDean
Messages: 69
Registered: July 2006
Member
On Mar 11, 1:33 pm, llo <bernat.puigdomen...@gmail.com> wrote:
> I am working on a project where I will be receiving measurements from
> the Global
> Positioning System, presumably latitude and longitude measurements,
> and I will
> need to calculate the distances between the measurement points. The
> measurements
> will all be taken over a region of only a few miles so I guess I could
> assume
> the earth is flat over this region and just calculate the straight
> line
> distance.
>
> But I was wondering if anyone could help me with a more mathematically
> rigorous method for calculating distance from pairs of latitude/
> longitude
> measurements?
>
> thanks,
>
> llo

dito to MAP_2POINTS and don't forget about LL2RBE from JHU/APL
distribution.

Kelly Dean
Fort Collins, CO
Re: how to calculate distance from pairs of latitude/longitude measurements? [message #65607 is a reply to message #65606] Wed, 11 March 2009 13:33 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
llo writes:

> I tried the following formula I found in your link:
>
> Distance between points
>
> The great circle distance d between two points with coordinates
> {lat1,lon1} and {lat2,lon2} is given by:
>
> d=acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2 ))
>
> A mathematically equivalent formula, which is less subject to rounding
> error for short distances is:
>
> d=2*asin(sqrt((sin((lat1-lat2)/2))^2 + cos(lat1)*cos(lat2)*(sin((lon1-
> lon2)/2))^2))
>
> the result is 0.8777. 0.8777 distance from montreal to albany ????

Try MAP_2POINTS in the IDL distribution.

Cheers,

David

--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: how to calculate distance from pairs of latitude/longitude measurements? [message #65608 is a reply to message #65607] Wed, 11 March 2009 13:21 Go to previous message
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
I tried the following formula I found in your link:

Distance between points

The great circle distance d between two points with coordinates
{lat1,lon1} and {lat2,lon2} is given by:

d=acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2 ))

A mathematically equivalent formula, which is less subject to rounding
error for short distances is:

d=2*asin(sqrt((sin((lat1-lat2)/2))^2 + cos(lat1)*cos(lat2)*(sin((lon1-
lon2)/2))^2))

the result is 0.8777. 0.8777 distance from montreal to albany ????

Doesn't works !
Re: how to calculate distance from pairs of latitude/longitude measurements? [message #65609 is a reply to message #65608] Wed, 11 March 2009 13:07 Go to previous message
Bruce Bowler is currently offline  Bruce Bowler
Messages: 128
Registered: September 1998
Senior Member
On Wed, 11 Mar 2009 12:49:41 -0700, llo wrote:

> I found MAP_PROJ_FORDWARD function to convert lat/lon to cartesian
> coordinates. So, calculate the distance between 2 cartesian points it's
> eaasy.
>
> The problem is when I use this function. The following problem ocurs:
>
> alb_cart=MAP_PROJ_FORWARD(-73.83,42.70) % MAP_PROJ_FORWARD: Value of
> Projection index is out of allowed range. % Execution halted at: $MAIN$
>
> (-73.83,42.70) are a valid lat/lon coordinates of station situated in
> Albany, USA.
> MAP_STRUCTURE is required to use this function (MAP_PROJ_FORWARD) but I
> don't know which mapping projection use.
>
> Any suggestions !?

Eqn's for doing anything you want with lats and longs can be found here...

http://williams.best.vwh.net/avform.htm

Converting them to IDL is left as an exercise for the reader (warning -
be careful with your signs if you use his formulae, the fly-boys appear
to be out of step with the rest of the world :-)

Bruce
Re: how to calculate distance from pairs of latitude/longitude measurements? [message #65610 is a reply to message #65609] Wed, 11 March 2009 12:49 Go to previous message
natha is currently offline  natha
Messages: 482
Registered: October 2007
Senior Member
I found MAP_PROJ_FORDWARD function to convert lat/lon to cartesian
coordinates. So, calculate the distance between 2 cartesian points
it's eaasy.

The problem is when I use this function. The following problem ocurs:

alb_cart=MAP_PROJ_FORWARD(-73.83,42.70)
% MAP_PROJ_FORWARD: Value of Projection index is out of allowed range.
% Execution halted at: $MAIN$

(-73.83,42.70) are a valid lat/lon coordinates of station situated in
Albany, USA.
MAP_STRUCTURE is required to use this function (MAP_PROJ_FORWARD) but
I don't know which mapping projection use.

Any suggestions !?
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: OpenADDE and IDL
Next Topic: Need Help Resolving ENDIF Errors

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 11:07:40 PDT 2025

Total time taken to generate the page: 0.64414 seconds