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

Home » Public Forums » archive » Get Latitude and Longitude from Tiff files
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
Get Latitude and Longitude from Tiff files [message #54546] Tue, 26 June 2007 18:52 Go to next message
Lucia is currently offline  Lucia
Messages: 5
Registered: June 2007
Junior Member
I wonder how to get latitude and longitude of each point of the files
(such as tiff format) that have already included detailed projection
parameters. Thank you !
Re: Get Latitude and Longitude from Tiff files [message #54752 is a reply to message #54546] Thu, 05 July 2007 00:26 Go to previous message
titan is currently offline  titan
Messages: 59
Registered: March 2006
Member
to kBob:
the tiff image I'm referring has been obtained using ENVI georeference
tool from input geometry.
that's why, probably, you haven't seen this in any GeoTIFF before.
could you please be a little bit clear when you say "An Affine
Transformation takes a 4x4 matrix to do the conversion from pixel to
degrees"?

to Lucia:
I have tried to use the David Fanning's instructions but unfortunately
the structure I have from my geotiff don't match to the ones you
have.


Could someone tell me if I can add other informations to my geotiff? I
mean in order to obtain those info in the geotag structure mentioned
in the code above xscale, yscale, tp ?

Thank you
Re: Get Latitude and Longitude from Tiff files [message #54763 is a reply to message #54546] Tue, 03 July 2007 23:24 Go to previous message
Lucia is currently offline  Lucia
Messages: 5
Registered: June 2007
Junior Member
Oh,yes!I haven't flinged FORTRAN away. Thanks a lot for David's
instruction!
Re: Get Latitude and Longitude from Tiff files [message #54770 is a reply to message #54546] Tue, 03 July 2007 20:18 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Lucia includes the following FOR loops in the example code:

> for i=1,s[0]-1 do begin
> lon[i]=xorigin+xscale*i
> endfor
>
> for i=1,s[1]-1 do begin
> lat[i]=yorigin-yscale*i
> endfor

Yikes! Here are a couple of cases where you almost
get vectorization for free. Help stamp out FORTRAN
coding in IDL!!!

lon = xorigin + xscale * Indgen(s[1])
lat = yorigin - yscale * Indgen(s[0])

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: Get Latitude and Longitude from Tiff files [message #54771 is a reply to message #54546] Tue, 03 July 2007 20:08 Go to previous message
Lucia is currently offline  Lucia
Messages: 5
Registered: June 2007
Junior Member
According to David Fanning's instruction, I have found a method that
can obtain latitude and longitude of each of point of GeoTIFF.
The source code is as follows.

pro get_latlon
filename='F:\data\A2007098.0235\mod43.Albedo_BSA_Band1.tif'

image = Read_Tiff(filename, GEOTIFF=geotag) ; GeoTIFF info in
"geotag" structure.
image = Reverse(image, 2) / 10000 ; Reverse Y direction, divide by
10000 to give correct values

; Find the image dimensions. Will need later.
s = Size(image, /Dimensions)
UTM_Map = MAP_PROJ_INIT('UTM', CENTER_LAT=0.0,
CENTER_LON=0.0,ZONE=50,datum=8,/gctp)
; Calculate corner points from GeoTIFF structure obtained from file.
xscale = geotag.ModelPixelScaleTag[0]
yscale = geotag.ModelPixelScaleTag[1]
tp = geotag.ModelTiePointTag

xOrigin = tp[3]
yOrigin = tp[4]

lon=fltarr(s[0])
lat=fltarr(s[1])
lat[0]=xorigin
lon[0]=yorigin

for i=1,s[0]-1 do begin
lon[i]=xorigin+xscale*i
endfor

for i=1,s[1]-1 do begin
lat[i]=yorigin-yscale*i
endfor

lat=transpose(lat)
lat=rebin(lat,s[0],s[1],/sample)
lon=rebin(lon,s[0],s[1],/sample)
latitude=fltarr(s[0],s[1])
longitude=fltarr(s[0],s[1])

for i=0,s[0]-1 do begin
lat1=lat[i,*]
lon1=lon[i,*]
a = MAP_PROJ_INVERSE(lon1,lat1,map_structure=UTM_Map)
longitude[i,*]=a[0,*]
latitude[i,*]=a[1,*]
endfor

filename='F:\data\A2007098.0235\latitude.dat'
openw,lun,filename,/get_lun
writeu,lun,latitude
free_lun,lun
filename='F:\data\A2007098.0235\longitude.dat'
openw,lun,filename,/get_lun
writeu,lun,longitude
free_lun,lun

end

^v^
Re: Get Latitude and Longitude from Tiff files [message #54774 is a reply to message #54546] Tue, 03 July 2007 13:17 Go to previous message
KRDean is currently offline  KRDean
Messages: 69
Registered: July 2006
Member
On Jul 3, 2:08 am, titan <thunder...@inwind.it> wrote:
> On Jun 27, 5:33 am, David Fanning <n...@dfanning.com> wrote:
>
>
>
>
>
>> Lucia writes:
>>> I wonder how to get latitude and longitude of each point of the files
>>> (such as tiff format) that have already included detailed projection
>>> parameters.
>
>> I presume you mean a GEOTiff file, not just a TIFF file.
>> You can presumably pull the information you need out of
>> the GeoTiff file itself. Here is an example written for
>> a slightly different reason that will give you some idea
>> of how to go about this:
>
>> http://www.dfanning.com/map_tips/geotiffreg.html
>
>> 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.")
>
> I have the same problem and I tried to follow the example mentioned
> before but unfortunately the informations I have are different:
> GeoTiff image Structure
> ** Structure <9d0b28c>, 6 tags, length=140, data length=138, refs=1:
> MODELTRANSFORMATIONTAG
> DOUBLE Array[4, 4]
> GTMODELTYPEGEOKEY
> INT 2
> GTRASTERTYPEGEOKEY
> INT 1
> GEOGRAPHICTYPEGEOKEY
> INT 4326
> GEOGLINEARUNITSGEOKEY
> INT 9001
> GEOGANGULARUNITSGEOKEY
> INT 9102
>
> In this case are there any possibilities to obtain latitude and
> longitude of each point of the GEOtiff image??
> Thank you- Hide quoted text -
>
> - Show quoted text -

Well...

GTMODELTYPEGEOKEY : 2 : Geographic
GTRASTERTYPEGEOKEY : 1 : Pixel is Area
GEOGRAPHICTYPEGEOKEY : 4326 : WGS 84
GEOGLINEARUNITSGEOKEY : 9001 : meter
GEOGANGULARUNITSGEOKEY : 9102 : degree

This tag is considered obsolete by the Cartographic Application Group.

MODELTRANSFORMATIONTAG

According to the IDL Help, this is a 4x4 matrix of doubles.

I haven't seen this in any GeoTIFF that I played around with, but the
tags seem reasonable to perform some kind of pixel to degree
computation. An Affine Transformation takes a 4x4 matrix to do the
conversion from pixel to degrees. Try that!

Kelly Dean
Fort Collins, CO
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL ION
Next Topic: Re: how to use Mosaic_doit procedure

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

Current Time: Thu Oct 09 21:21:46 PDT 2025

Total time taken to generate the page: 0.00840 seconds