Automatically Register GeoTIFF Images

QUESTION: I'd like to open a GeoTIFF image in IDL and have it automatically be georegistered so I can read latitude and longitude coordinates directly from it. Is there a way to do that in IDL?

ANSWER: Starting with IDL 7.1, if you set your IDL Workbench preferences up so you Visualize Images on Open, you can open a GeoTIFF image from the File->Open menu and have it automatically opened and georegistered in an iImage tool. Note that if you open a GeoTIFF file directly into an iImage tool, the image is not georegistered. You must open the image file with iOpen or from the Open menu selection.

If you would prefer not to use iTools to do this, it is also possible to automatically georegister an image by opening the GeoTIFF file with either of the Coyote Library routines SelectImage or ImgWin. These programs take advantage of a Catalyst Library routine, MapCoord, that creates a map projection data coordinate system for an image. This means both the Coyote and Catalyst Libraries must be on your IDL path.

If you would like to see how this has done, I have made a compressed example GeoTIFF file available for download. Simply uncompress the file and extract an GeoTIFF file named AF03sep15b.n16-VIg.gz. This is an AVHRR NDVI data image in GeoTIFF format.

Once the file is uncompressed, you can open it by selecting it with SelectImage. If you simply wish to open the file with SelectImage, the geoTIFF tags are returned in an IDL structure via the GEOTIFF keyword. In addition, the geoTIFF IDL structure is saved at the main IDL level for further examination in a variable named geotiff.

   IDL> image = SelectImage(GEOTIFF=geo)
   IDL> Help, geo, geotiff
      GEO             STRUCT    = ->  Array[1]
      GEOTIFF         STRUCT    = ->  Array[1]

You can see the geotiff structure in more detail by setting the STRUCTURE keyword on the Help command.

   IDL> Help, geotiff, /STRUCTURE

You see what SelectImage looks like in the figure below.

SelectImage used to read GeoTiff image.
SelectImage used to read GeoTIFF image.

If you wish to read the image with SelectImage and immediately display it with ImgWin, then set the DISPLAY keyword to SelectImage.

   IDL> image = SelectImage(/DISPLAY)

The image is now read (and returned), but also displayed in a georegisted form in ImgWin. As you move your cursor in the ImgWin window, the data coordinates reflect the longitude and latitude location of the cursor in the image. Note that ImgWin is a completely resizeable graphics window, and that you have the ability, via menu selections to perform a number of image manipulations, and to save the image in a variety of hardcopy formats, include JPEG, PNG, and PostScript.

ImgWin used to display the GeoTiff image.
With the DISPLAY keyword selected, SelectImage immediately
displays the GeoTIFF image.

If you prefer, you can open the GeoTIFF image directly into ImgWin. Either call ImgWin with no arguments and select the GeoTIFF file, or pass it the name of the GeoTIFF file directly.

   IDL> ImgWin, 'AF03sep15b.n16-VIg.tif'

In either case, the georegistered image is displayed.

How Is It Done?

The secret behind the ability to display georegistered images is a Catalyst utility routine named GeoCoord. This routine translates the GeoTIFF structure returned by the routines Query_TIFF and Read_TIFF into a map coordinate object, named MapCoord. This map coordinate object is then used as a data coordinate object for an image object, and it is this image object that is then passed to ImgWin. This makes it possible to create different kinds of image overlays. For example, here is how you might add a map grid, and country outlines to the image above.

   mapCoord = GeoCoord('AF03sep15b.n16-VIg.tif')
   grid = Obj_New('Map_Grid', MAP_OBJECT=mapCoord, COLOR='indian red')
   countries = Obj_New('Map_Outline', MAP_OBJECT=mapCoord, Color='charcoal', /COUNTRIES)
   mapCoord -> SetProperty, GRID_OBJECT=grid, OUTLINE_OBJECT=countries
   colors = Obj_New('CatColors', /BREWER, INDEX=2)
   imageObj = Obj_New('ScaleImage', image, COORD_OBJECT=mapCoord, COLOR_OBJECT=colors)
   ImgWin, imageObj, TITLE='AF03sep15b.n16-VIg.tif', /WIN_KEEP_ASPECT

You see the result in the figure below.

ImgWin used to display the GeoTiff image.
Image displays are easily customized.

Please Note: Many programs changed as a result of adding this functionality to the Coyote Library routines. To make use of this functionality you must update the following Coyote and Catalyst Library programs to the August 30, 2009 version.

  1. ImgWin
  2. SelectImage
  3. MapGrid__Define
  4. MapOutline__Define
  5. MapPlotS__Define
  6. CatContainer__Define
  7. MapCoord__Define
  8. GeoCoord

Using Coyote Graphics Routines

Many of these ideas have been incorporated into Coyote Graphics routines directly. So, without installing the Catalyst Library, it is now possible to display this image in a resizeable graphics window, in which you can save the fine to PostScript, PDF, and five different types of raster file output, with these simple commands.

   file = 'AF03sep15b.n16-VIg.tif'
   cgLoadCT, 4, /Brewer, /Reverse
   TVLCT, cgColor('white', /Triple), 0
   void = cgGeoMap(file, /Display, /Continents, /Grid, /Clip)

You see the result in the figure below.

Using Coyote Graphics routines to automatically display GeoTiff files.
Using Coyote Graphics routines to automatically display GeoTiff files.

Version of IDL used to prepare this article: IDL 7.0.3.

Web Coyote's Guide to IDL Programming