Re: matching 2 grids [message #47843] |
Wed, 08 March 2006 21:02  |
envi35@yahoo.ca
Messages: 48 Registered: March 2005
|
Member |
|
|
Hi Mark,
I just downloaded the motley library and unpacked the files to a
directory, and added it to my IDL path as suggested. But when I type
"mgh_motley" in IDL command line, I got complie error in Line 53, line
147.
I'm using IDL 6.2 in windows 2000. This is the first time I use a
library. I must haven't done it right. Could you tell me what I should
do?
Thanks, Jenny
|
|
|
Re: matching 2 grids [message #47848 is a reply to message #47843] |
Wed, 08 March 2006 17:53   |
Robert Moss
Messages: 74 Registered: February 1996
|
Member |
|
|
Jenny wrote:
> Hi Mark,
>
> Thanks for your reply!
>
> Sorry I'm not very clear about my problem. But it seems more complex
> than the one posted yesterday. They are 2-D arrays. I have 2 files for
> grid1: 600*600 array for lat1, and 600*600 array for lon1, one
> lat1/lon1 pair (smae coordinate in the array) represents the true
> location on earth. So generally lat1 increase along a column, and also
> slightly different along a row. Same for lon1, increase along a row,
> slightly different along a column. I think grid1 was produced from
> polar stereographic projection, so that they are not equally spaced
> lat/lon pairs. grid2 is a polygon shaped subset of grid1, they are also
> one 2-d array for lat2 and one for lon2 (say 100*120 with 0 filled in
> some places), but not exactly the same values as those in grid1, grid2
> was defined in a different projection. What I want is to find the
> closest lat1/lon1 for each of the lat2/lon2 based on the geographic
> location the lat/lon represents.
>
> I'll check the Motley library. I'd appreciate any further insights!
>
> -Jenny
>
This may not be what you are shooting for, but here's my idea: Use grid1
as an IGM to create a GLT for image1. Convert the data in grid2 to
geographic coordinates using ENVI_CONVERT_PROJECTON_COORDINATES if they
are not already. Then use ENVI_CONVERT_FILE_COORDINATES to convert the
new grid2 geographic coordinates into a file location in the grid1 GLT.
From there you can get the exact pixels that were used in grid1 that
correspond to grid2.
This all assumes you need to know the precise coordinates in the
original grid1 file so you can relate them to unaltered raw image data
from which grid1 was derived. If that is not what you are trying to do,
there is almost certainly a simpler way.
Robert Moss, PhD
|
|
|
Re: matching 2 grids [message #47849 is a reply to message #47848] |
Wed, 08 March 2006 17:50   |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
Jenny wrote:
> Hi Mark,
>
> Sorry I'm not very clear about my problem. But it seems more complex
> than the one posted yesterday. They are 2-D arrays. I have 2 files for
> grid1: 600*600 array for lat1, and 600*600 array for lon1, one
> lat1/lon1 pair (smae coordinate in the array) represents the true
> location on earth. So generally lat1 increase along a column, and also
> slightly different along a row. Same for lon1, increase along a row,
> slightly different along a column. I think grid1 was produced from
> polar stereographic projection, so that they are not equally spaced
> lat/lon pairs. grid2 is a polygon shaped subset of grid1, they are also
> one 2-d array for lat2 and one for lon2 (say 100*120 with 0 filled in
> some places), but not exactly the same values as those in grid1, grid2
> was defined in a different projection. What I want is to find the
> closest lat1/lon1 for each of the lat2/lon2 based on the geographic
> location the lat/lon represents.
Yes, it's what I called a 2-D location problem in my previous post and
it can be handled by MGH_LOCATE2 or MGH_LOCATE2A (the former is faster
when the number of points in grid2 is large, the latter when it is
small). Examples of how to use these are in MGH_EXAMPLE_LOCATE.
What MGH_LOCATE2 will give you, for each point in grid2, is a 2-element
floating-point vector describing its position in the 2D "index space" of
grid1. If you round this vector to the nearest integer, that will be the
location of the nearest point of grid1.
--
Mark Hadfield "Kei puwaha te tai nei, Hoea tahi tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
|
|
|
Re: matching 2 grids [message #47850 is a reply to message #47849] |
Wed, 08 March 2006 17:01   |
envi35@yahoo.ca
Messages: 48 Registered: March 2005
|
Member |
|
|
Hi Mark,
Thanks for your reply!
Sorry I'm not very clear about my problem. But it seems more complex
than the one posted yesterday. They are 2-D arrays. I have 2 files for
grid1: 600*600 array for lat1, and 600*600 array for lon1, one
lat1/lon1 pair (smae coordinate in the array) represents the true
location on earth. So generally lat1 increase along a column, and also
slightly different along a row. Same for lon1, increase along a row,
slightly different along a column. I think grid1 was produced from
polar stereographic projection, so that they are not equally spaced
lat/lon pairs. grid2 is a polygon shaped subset of grid1, they are also
one 2-d array for lat2 and one for lon2 (say 100*120 with 0 filled in
some places), but not exactly the same values as those in grid1, grid2
was defined in a different projection. What I want is to find the
closest lat1/lon1 for each of the lat2/lon2 based on the geographic
location the lat/lon represents.
I'll check the Motley library. I'd appreciate any further insights!
-Jenny
|
|
|
Re: matching 2 grids [message #47853 is a reply to message #47850] |
Wed, 08 March 2006 16:17   |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
Jenny wrote:
> Hi all,
>
> I have 2 sets of lat/lon pairs in different grids - grid1 and grid2,
> both in irregular shape and I've filled some zero numbers to make them
> regular. grid2 is a subset of grid1. I want to find the coordinates of
> x1,y1 in grid1 (lat1/lon1) which are closest to each of the nonzero
> lat2/lon2 paris in grid2.
>
> I made a programm with several loops, it is kind of did what I want,
> but it is very slow and the boundary is not tidy. my grid1 is 600*600,
> and I have 10 grid2 to process.
>
> Is there an IDL function that I could use in this case?
The key to solving a problems like this is to make use of any geometric
structure in the grid (and here I mean the grid you're trying to locate
yourself in, ie. grid1). How irregular is grid1? I presume it's not
rectangular (ie. lon varies in one direction, lat in the other). Is it
curvilinear? Ie, does it look like a rectangular grid that has been
rotated and deformed? Or are the grid1 points just scattered with no
particular relation to each other?
For a rectangular grid, you would have a pair of 1-D location problems
of the sort that were discussed yesterday in this group under the title
"Interpolating a regular grid".
For a curvilinear grid you have a 2-D location problem. As my message
yesterday said, the Motley library has 1-D and 2-D location functions.
For a scattered set of points, I don't know. I suspect you could
approach it by first constructing a Delaunay triangulation for grid1
(see function TRIANGULATE) and then performing a nearest-neighbour
interpolation with GRIDDATA. Give each grid1 point a unique data value,
then the interpolated value on the grid2 points is the value associated
with the nearest grid1 point--something like that.
--
Mark Hadfield "Kei puwaha te tai nei, Hoea tahi tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
|
|
|
Re: matching 2 grids [message #47978 is a reply to message #47843] |
Thu, 09 March 2006 07:29  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Jenny writes:
> I just downloaded the motley library and unpacked the files to a
> directory, and added it to my IDL path as suggested. But when I type
> "mgh_motley" in IDL command line, I got complie error in Line 53, line
> 147.
> I'm using IDL 6.2 in windows 2000. This is the first time I use a
> library. I must haven't done it right. Could you tell me what I should
> do?
Try this:
IDL> @mgh_motley
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: matching 2 grids [message #47992 is a reply to message #47843] |
Wed, 08 March 2006 21:57  |
envi35@yahoo.ca
Messages: 48 Registered: March 2005
|
Member |
|
|
Hi Mark,
My last post about the compile error doesn't seem to affect me to use
the functions in the Motley library, so could be neglected if you like
:). But I'm not familar with the "index space", I didn't find
mgh_example_locate2.pro in the library. Are Xin and Yin in mgh_locate2
the index of my lat2 and lon2? how could I get them? could I avoid the
ponits of zeros in the meanwhile?
Sorry for these simple questions.
Thanks again,
Jenny
|
|
|