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

Home » Public Forums » archive » Re: Find pixel based on latitude/longitude.
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: Find pixel based on latitude/longitude. [message #79006] Thu, 26 January 2012 02:17
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
On 01/26/2012 07:53 AM, Craig Markwardt wrote:
> David's method is "nearest neighbor" interpolation. If you want to
> get slightly fancier, use linear interpolation with INTERPOLATE().

Fancier, yes, but not allways scientifically valid ;-) It depends on the
spatial validity of your grid points and the kind of data you are
looking at. For SST, linear should more or less do the job...
Re: Find pixel based on latitude/longitude. [message #79008 is a reply to message #79006] Wed, 25 January 2012 22:53 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Jan 25, 10:37 pm, David Fanning <n...@dfanning.com> wrote:
> Daniel Otis writes:
>> This is a very basic question, but I am struggling to find a good
>> solution. I have image arrays and want to find a pixel and a line
>> value based on a latitude and a longitude.
>
>> For example, a global SST array is 2D (8640x4320). I have a 1D array
>> of latitudes(4320) and 1D array of longitudes(8640). Based on depth
>> and other considerations, I have a latitude value and a longitude
>> value where I want to extract data and I need to find the closest
>> pixel.
>
>> I can't use a WHERE command because my desired lat/lon values don't
>> exactly correspond to those in the lat/lon arrays. I just want to find
>> the closest pixel in the 2D array based on the lat and lon that I
>> provide.
>
>> This seems simple, but I have not been able to find a good solution.
>> Any ideas are appreciated. Thanks.
>
> latindex = Value_Locate(lats, mylat)
> lonindex = Value_Locate(lons, mylon)
> valueIwant = image[lonindex, latindex]

David's method is "nearest neighbor" interpolation. If you want to
get slightly fancier, use linear interpolation with INTERPOLATE().

Craig
Re: Find pixel based on latitude/longitude. [message #79009 is a reply to message #79008] Wed, 25 January 2012 19:37 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Daniel Otis writes:

> This is a very basic question, but I am struggling to find a good
> solution. I have image arrays and want to find a pixel and a line
> value based on a latitude and a longitude.
>
> For example, a global SST array is 2D (8640x4320). I have a 1D array
> of latitudes(4320) and 1D array of longitudes(8640). Based on depth
> and other considerations, I have a latitude value and a longitude
> value where I want to extract data and I need to find the closest
> pixel.
>
> I can't use a WHERE command because my desired lat/lon values don't
> exactly correspond to those in the lat/lon arrays. I just want to find
> the closest pixel in the 2D array based on the lat and lon that I
> provide.
>
> This seems simple, but I have not been able to find a good solution.
> Any ideas are appreciated. Thanks.

latindex = Value_Locate(lats, mylat)
lonindex = Value_Locate(lons, mylon)
valueIwant = image[lonindex, latindex]

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Find pixel based on latitude/longitude.
Next Topic: Re: cgWindow Test Volunteers

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

Current Time: Wed Oct 08 13:44:18 PDT 2025

Total time taken to generate the page: 0.00602 seconds