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

Home » Public Forums » archive » Re: Retrieve pixel values from GeoTIFF
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: Retrieve pixel values from GeoTIFF [message #73784] Sat, 27 November 2010 13:03
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

>
> David Fanning writes:
>
>>
>> mankoff writes:
>>
>>> David: I've also tried using your GeoCoord object, and can display the
>>> graphic and coastlines just fine, but again, am stuck at the step of
>>> "convert (lon,lat)=(-100,-75) to (x,y) for indexing into the original
>>> TIF".
>>
>> mapCoord = GeoCoord('mygeotiff_file.tif')
>> mapStruct = mapCoord -> GetMapStructure()
>> xy = Map_Proj_Forward(lon,lat, Map_Structure=mapStruct)
>> x = xy[0]
>> y = xy[1]
>
> Oh, wait! You said you want to index into the original
> image. (My son is bugging me about bying a car today,
> so I'm distracted. :-)
>
> In addition to the above, I would do this.
>
> mapCoord -> GetProperty, XRANGE=xr, YRANGE=xy
> s = Size(image, /Dimensions)
> xvec = Scale_Vector(Findgen(s[0]), xr[0, xr[1])
> xindex = Value_Locate(xvec, x)
> yvec = Scale_Vector(Findgen(s[1]), yr[0], yr[1])
> yindex = Value_Locate(yvec, y)
>
> Then,
>
> Print, image[xindex, yindex]

Geez! Be sure to type that code with one eye closed!
I have to go look at cars. If you can't figure it out,
I do it right when I return. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Retrieve pixel values from GeoTIFF [message #73785 is a reply to message #73784] Sat, 27 November 2010 12:59 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

>
> mankoff writes:
>
>> David: I've also tried using your GeoCoord object, and can display the
>> graphic and coastlines just fine, but again, am stuck at the step of
>> "convert (lon,lat)=(-100,-75) to (x,y) for indexing into the original
>> TIF".
>
> mapCoord = GeoCoord('mygeotiff_file.tif')
> mapStruct = mapCoord -> GetMapStructure()
> xy = Map_Proj_Forward(lon,lat, Map_Structure=mapStruct)
> x = xy[0]
> y = xy[1]

Oh, wait! You said you want to index into the original
image. (My son is bugging me about bying a car today,
so I'm distracted. :-)

In addition to the above, I would do this.

mapCoord -> GetProperty, XRANGE=xr, YRANGE=xy
s = Size(image, /Dimensions)
xvec = Scale_Vector(Findgen(s[0]), xr[0, xr[1])
xindex = Value_Locate(xvec, x)
yvec = Scale_Vector(Findgen(s[1]), yr[0], yr[1])
yindex = Value_Locate(yvec, y)

Then,

Print, image[xindex, yindex]

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Retrieve pixel values from GeoTIFF [message #73786 is a reply to message #73785] Sat, 27 November 2010 12:52 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
mankoff writes:

> David: I've also tried using your GeoCoord object, and can display the
> graphic and coastlines just fine, but again, am stuck at the step of
> "convert (lon,lat)=(-100,-75) to (x,y) for indexing into the original
> TIF".

mapCoord = GeoCoord('mygeotiff_file.tif')
mapStruct = mapCoord -> GetMapStructure()
xy = Map_Proj_Forward(lon,lat, Map_Structure=mapStruct)
x = xy[0]
y = xy[1]

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Retrieve pixel values from GeoTIFF [message #73787 is a reply to message #73786] Sat, 27 November 2010 12:45 Go to previous message
mankoff is currently offline  mankoff
Messages: 131
Registered: March 2004
Senior Member
On Nov 27, 12:06 pm, Paulo Penteado <pp.pente...@gmail.com> wrote:
> On Nov 27, 4:53 pm, mankoff <mank...@gmail.com> wrote:
>
>> I'm trying to get the pixel values (color) from a GeoTIFF file when I
>> have lat,lon arrays. I have the projection set up using MAP_PROJ_INIT,
>> and using MAP_PROJ_FORWARD I can convert from my latitude and
>> longitude to map coordinates, but the map coordinates appear to be in
>> units meter from some reference location. What is the best routine to
>> convert from lat,lon (or u,v) to x,y indices?
>
> It seems that map_proj_forward() can do what you want, you are just
> not giving it the right projection parameters. What is in the geotiff
> structure?

Working through a simpler well-documented example (thanks to David)
here:
http://www.dfanning.com/map_tips/iceshelf.html

The "xy" returned from MAP_PROJ_FORWARD contains negative values, so
this cannot be indices into the image. Should I be using CONVERT_COORD
to go from DATA to DEVICE with the xy array?

David: I've also tried using your GeoCoord object, and can display the
graphic and coastlines just fine, but again, am stuck at the step of
"convert (lon,lat)=(-100,-75) to (x,y) for indexing into the original
TIF".

-k.
Re: Retrieve pixel values from GeoTIFF [message #73789 is a reply to message #73787] Sat, 27 November 2010 12:13 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
mankoff writes:

> I'm trying to get the pixel values (color) from a GeoTIFF file when I
> have lat,lon arrays. I have the projection set up using MAP_PROJ_INIT,
> and using MAP_PROJ_FORWARD I can convert from my latitude and
> longitude to map coordinates, but the map coordinates appear to be in
> units meter from some reference location. What is the best routine to
> convert from lat,lon (or u,v) to x,y indices?

I use GeoCoord from the Catalyst Library. It reads the
GeoTIFF file, and sets everything up for you automatically. :-)

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Retrieve pixel values from GeoTIFF [message #73790 is a reply to message #73789] Sat, 27 November 2010 12:06 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Nov 27, 4:53 pm, mankoff <mank...@gmail.com> wrote:
> I'm trying to get the pixel values (color) from a GeoTIFF file when I
> have lat,lon arrays. I have the projection set up using MAP_PROJ_INIT,
> and using MAP_PROJ_FORWARD I can convert from my latitude and
> longitude to map coordinates, but the map coordinates appear to be in
> units meter from some reference location. What is the best routine to
> convert from lat,lon (or u,v) to x,y indices?

It seems that map_proj_forward() can do what you want, you are just
not giving it the right projection parameters. What is in the geotiff
structure?
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Retrieve pixel values from GeoTIFF
Next Topic: IDL syntax coloring in BBEdit

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

Current Time: Sat Oct 11 15:02:09 PDT 2025

Total time taken to generate the page: 0.72063 seconds