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

Home » Public Forums » archive » Re: locating the closest values?
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: locating the closest values? [message #80658] Wed, 27 June 2012 08:51
cgguido is currently offline  cgguido
Messages: 195
Registered: August 2005
Senior Member
Ah yes, pesky distances on a sphere.... Also, I meant to say distance_measure.

G
Re: locating the closest values? [message #80671 is a reply to message #80658] Tue, 26 June 2012 18:35 Go to previous message
Russell Ryan is currently offline  Russell Ryan
Messages: 122
Registered: May 2012
Senior Member
On Tuesday, June 26, 2012 5:28:56 PM UTC-4, Mats Löfdahl wrote:
> Den tisdagen den 26:e juni 2012 kl. 22:55:34 UTC+2 skrev anil:
>> Hi,
>> I have two datasets/files. 1st one contains the values i want to find
>> (latitudes and longitudes) and the second file contains 3 columns as
>> longitude latitude and depth.
>> What i want to do is to read my desired values from file 1 and find
>> the closest values in file 2 and the corresponding 3rd column(depth)
>> from file 2. here is what i did:
>> 1st file:
>> 42.25 30.57
>> 41.17 32.58
>> ......
>> 2nd file
>> 42.55 34.42 1000
>> 41.54 33.21 1500
>> .......
>> what i did is :
>>
>> difference1=abs(lon-desiredlon)
>> a1=min(difference1,index1)
>>
>> difference2=abs(lat-desiredlat)
>> a2=min(difference2,index2)
>>
>> in this case, lon(index1) and lat(index2) become my desired values. no
>> problem with that. but how do i get the 3rd column. i could not match
>> index1 and index2 with where function.
>> what am i missing here?
>
> Index1 and index2 are different because being close in one of lat and lon is not the same as being closest in both. I suspect what you want is something like a=min(sqrt(difference1^2+difference2^2),index), which should give you the index to the point with the shortest distance from the desired point. (You may want to scale the differences to length units first.)

So, that's going to work, but the distance you get "a" is probably not the minimum distance since you're working with angles. That said, you should look up the relevant equation for "great circle" distances to get the true minimum.
Re: locating the closest values? [message #80676 is a reply to message #80671] Tue, 26 June 2012 15:25 Go to previous message
cgguido is currently offline  cgguido
Messages: 195
Registered: August 2005
Senior Member
I'd use measure_distance to get them all in one go.... Then search for the minima...
Re: locating the closest values? [message #80678 is a reply to message #80676] Tue, 26 June 2012 14:50 Go to previous message
anil is currently offline  anil
Messages: 34
Registered: August 2009
Member
On Jun 27, 12:28 am, Mats Löfdahl <mats.lofd...@gmail.com> wrote:
> Den tisdagen den 26:e juni 2012 kl. 22:55:34 UTC+2 skrev anil:
>
>
>
>
>
>
>
>
>
>> Hi,
>> I have two datasets/files. 1st one contains the values i want to find
>> (latitudes and longitudes) and the second file contains 3 columns as
>> longitude latitude and depth.
>> What i want to do is to read my desired values from file 1 and find
>> the closest values in file 2 and the corresponding 3rd column(depth)
>> from file 2. here is what i did:
>> 1st file:
>> 42.25 30.57
>> 41.17 32.58
>> ......
>> 2nd file
>> 42.55 34.42 1000
>> 41.54 33.21 1500
>> .......
>> what i did is :
>
>> difference1=abs(lon-desiredlon)
>> a1=min(difference1,index1)
>
>> difference2=abs(lat-desiredlat)
>> a2=min(difference2,index2)
>
>> in this case, lon(index1) and lat(index2) become my desired values. no
>> problem with that. but how do i get the 3rd column. i could not match
>> index1 and index2 with where function.
>> what am i missing here?
>
> Index1 and index2 are different because being close in one of lat and lon is not the same as being closest in both. I suspect what you want is something like a=min(sqrt(difference1^2+difference2^2),index), which should give you the index to the point with the shortest distance from the desired point. (You may want to scale the differences to length units first.)

Thank you for your answer. I guess I just found it. it is as simple as
it is: where function :) :

c=where(lon eq lon(index1) and lat eq lat(index2))
this c is what i want. just the statement giving the exact locations.
Re: locating the closest values? [message #80680 is a reply to message #80678] Tue, 26 June 2012 14:28 Go to previous message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
Den tisdagen den 26:e juni 2012 kl. 22:55:34 UTC+2 skrev anil:
> Hi,
> I have two datasets/files. 1st one contains the values i want to find
> (latitudes and longitudes) and the second file contains 3 columns as
> longitude latitude and depth.
> What i want to do is to read my desired values from file 1 and find
> the closest values in file 2 and the corresponding 3rd column(depth)
> from file 2. here is what i did:
> 1st file:
> 42.25 30.57
> 41.17 32.58
> ......
> 2nd file
> 42.55 34.42 1000
> 41.54 33.21 1500
> .......
> what i did is :
>
> difference1=abs(lon-desiredlon)
> a1=min(difference1,index1)
>
> difference2=abs(lat-desiredlat)
> a2=min(difference2,index2)
>
> in this case, lon(index1) and lat(index2) become my desired values. no
> problem with that. but how do i get the 3rd column. i could not match
> index1 and index2 with where function.
> what am i missing here?

Index1 and index2 are different because being close in one of lat and lon is not the same as being closest in both. I suspect what you want is something like a=min(sqrt(difference1^2+difference2^2),index), which should give you the index to the point with the shortest distance from the desired point. (You may want to scale the differences to length units first.)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Problem with Parinfo on Craig B. Markwardt's MPFITPEAK
Next Topic: Marshall Perrin's library subreg.pro question

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

Current Time: Wed Oct 08 17:38:35 PDT 2025

Total time taken to generate the page: 0.00646 seconds