GeoTIFF Creation

A common method for creating raster data that can be ingested into a GIS system, is to encode the data into a GeoTIFF. A GeoTIFF is a TIFF image file, with geographic tags that allow the image to have a geographic presence.

In this tutorial we will cover:
1. Creating a TIFF from a bitmap using libtiff.
2. Creating metadata and a world file for the GeoTIFF using libgeotiff.
3. Encoding the TIFF and metadata to make the GeoTIFF using libgeotiff.
4. Checking the correctness of the GeoTIFF.

1/12 Environment
Red Hat Linux 3.2.3-58
GNU Make version 3.79.1
gcc version 3.2.3
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Apache Tomcat 6.0.14
GeoServer 1.5.4a
libtiff 3.8.2
libgeotiff 1.2.4

2/12 Download/Install libtiff:
http://www.libtiff.org/
tiff-3.8.2.tar.gz

Go ahead and download the latest version of libtiff. Libtiff is a library that allows manipulation of TIFFS and is required for the use of libgeotiff. Below are cursory commands for installation, commands may vary depending on environment:

$ gzip -rd tiff-3.8.2.tar.gz
$ tar -xf tiff-3.8.2.tar
$ cd tiff-3.8.2
$ ./configure --prefix=/home/mydir/libtiff/
$ make
$ make install

3/12 Download/Install libgeotiff:
http://www.remotesensing.org/geotiff/geotiff.html
libgeotiff-1.2.4.tar.gz

Download the latest version of libgeotiff. Libgeotiff is a library that allows manipulation of GeoTIFFS. Below are cursory commands for installation, commands may vary depending on environment:

$ gzip -rd libgeotiff-1.2.4.tar.gz
$ tar -xf libgeotiff-1.2.4.tar
$ cd libgeotiff-1.2.4
$ ./configure --with-libtiff=/home/mydir/libtiff/
$ make

4/12 A World Map:
http://earthobservatory.nasa.gov/Newsroom/BlueMarble/
bluemarble.tif

GeoTIFF of the NASA Blue Marble. I made this using gdalwarp from one of the .ecws from NASA’s Blue Marble website. Great high level map, works fine for the weather applications I created it for. However, when you begin to zoom in, the image becomes pixelated. Perhaps we want some areas with more clarity, without having fine grain detail in the whole image.

5/12 A Detailed Area of Interest:
http://openaerialmap.hypercube.telascience.org/datasource/36/
santarosa

Santa Rosa Island off of Santa Barbara in California. This image is a screen shot from the OpenAerielMap website. Convert the bitmap to a TIFF. I would generally do this in Java with JAI, but we might as well use what we just compiled from libtiff:

$ /home/mydir/libtiff/bin/bmp2tiff santarosa.bmp santarosa.tif

6/12 Assess:
We have all the tools we need, and we have all of our sources files. Our goal is to take the TIFF we just made from a bitmap, and to geographically encode it, such that it can be overlaid on our Blue Marble to allow extra information for the area of interest.

7/12 Produce MetaData for the GeoTIFF:
http://www.remotesensing.org/geotiff/listgeo.html
metadata.txt

We can see all of the geospatial information that we need is already available.

$ /home/mydir/libgeotiff/bin/listgeo bluemarble.tif > metadata.txt
$ more metadata.txt
Geotiff_Information:
   Version: 1
   Key_Revision: 1.0
   Tagged_Information:
      ModelTiepointTag (2,3):
         0                0                0
         -180             90               0
      ModelPixelScaleTag (1,3):
         0.0833333333     0.0833333333     0
      End_Of_Tags.
   Keyed_Information:
      GTModelTypeGeoKey (Short,1): ModelTypeGeographic
      GTRasterTypeGeoKey (Short,1): RasterPixelIsArea
      GeographicTypeGeoKey (Short,1): GCS_WGS_84
      GeogCitationGeoKey (Ascii,7): "WGS 84"
      GeogAngularUnitsGeoKey (Short,1): Angular_Degree
      End_Of_Keys.
   End_Of_Geotiff.

GCS: 4326/WGS 84
Datum: 6326/World Geodetic System 1984
Ellipsoid: 7030/WGS 84 (6378137.00,6356752.31)
Prime Meridian: 8901/Greenwich (0.000000/  0d 0' 0.00"E)

Corner Coordinates:
Upper Left    (180d 0' 0.00"W, 90d 0' 0.00"N)
Lower Left    (180d 0' 0.00"W, 89d60' 0.00"S)
Upper Right   (179d60' 0.00"E, 90d 0' 0.00"N)
Lower Right   (179d60' 0.00"E, 89d60' 0.00"S)
Center        (  0d 0' 0.00"W,  0d 0' 0.00"N)

8/12 Produce a WorldFile for the GeoTIFF:
http://en.wikipedia.org/wiki/World_file
worldfile.tfw

The .tfw world file is a simple file that holds coordinate information for the GeoTIFF.

Line 1: A, pixel size in the x-direction in map units/pixel
Line 2: D: rotation about y-axis
Line 3: B: rotation about x-axis
Line 4: E: pixel size in the y-direction in map units, almost always negative
Line 5: C: x-coordinate of the center of the upper left pixel
Line 6: F: y-coordinate of the center of the upper left pixel

Line 2 and 3 can be zero, as there is going to be no rotation:

   X.XXXXXXXXXX
   0.0000000000
   0.0000000000
   X.XXXXXXXXXX
   X.XXXXXXXXXX
   X.XXXXXXXXXX

Using Google Earth, we can extrapolate the top left corner's coordinates. Using the highly scientificly accurate method of 'eyeballing', we compare Google Earth's Channel Island image, with what we think is the location of the top left corner of our TIFF. Zooming in to a comparable level of the GeoTIFF, as well as opening it and placing it on top of Google Earth itself often helps in this process. I've guessed it out to about 34.143 N 120.530 W.

   X.XXXXXXXXXX
   0.0000000000
   0.0000000000
   X.XXXXXXXXXX
-120.5301720000
  34.1439110000

The width in pixels is: 1096, the height in pixels is: 724.

The width of the GeoTIFF will have the right edge at ~-119.7273170376
120.5301720000 - 119.7273170376 = 1096 * Y
0.8028549624/1096 = Y
0.0007325319 = Y

The height of the GeoTIFF will have the bottom edge at ~33.6912860376

33.6912860376 - 34.1439110000 = 724 * X
-0.4526249624/724 = X
-0.0006251726 = X

   0.0007325319
   0.0000000000
   0.0000000000
  -0.0006251726
-120.5301720000
  34.1439110000

9/12 Produce the GeoTIFF Using geotifcp:
At this point one might wonder about the information in the metadata file that appears to make the world file moot. For the purpose of this tutorial I've used both files so that the reader can get an understanding of both. Geotifcp will allow the worldfile's tie point and scale information to take precedence.

$ /home/mydir/libgeotif/bin/geotifcp -e worldfile.tfw -g 
		metadata.txt santarosa.tif santarosageo.tif

10/12 Confirm:

$ listgeo santarosageo.tif
$ listgeo -tfw santarosageo.tif
$ more santarosageo.tfw

Everything seems to work as expected. Our new GeoTIFF is responding with the proper information.

11/12 Really Confirm:
GeoServer is an open source WMS/WFS server. OpenLayers is a JavaScript library that comes with GeoServer that allows a user to view a WMS/WFS input in a web page. We will load our basemap, and our generated GeoTIFF, as well as overlay them in a group to make sure that everything works as we expect.

Installation of Tomcat/GeoServer is beyond the scope of this article, but is well documented on their respective web pages.

a) Add bluemarble.tif as a coverage data store.
b) Add santarosageo.tif as a coverage data store.
c) Create a layer group with santarosageo.tif on top.

I'd love to show you some nice OpenLayers maps, however, my hosting package doesn't allow me to run GeoServer, and I'm not paying $50.00 a month just to drop a .war.

So take a look at the screenshots below:

1

2

The above screen shots are zoomed in our area of interest, our GeoTIFF is exactly where we expect it to be, with proper dimensions.

12/12 Complete:

Possible extensions:
a) Mosaic together the two files.
b) Properly integrate them into a single GeoTIFF.
c) Have the high resolution image only show up at a specific zoom level in the OpenLayers application.

Leave a Reply