GeoTIFF file creation with GDAL

From FSDeveloper Wiki
Jump to navigationJump to search

Now that the FsX resample tool can also read GeoTIFF files, it has become very interesting to use these for your photo scenery. The main advantage of using GeoTIFF files is that they contain the placement information of your photo, so that means you don't have to specify all those numbers in the INF file.

But what do you do when you don't have your images in the GeoTIFF format? Or when you have images that are not in the WGS84 projection required by resample? In those cases you need some tools to create the correct GeoTIFF files for you.

In this article I will describe how you can use the FwTools toolkit to perform such tasks. Of course there will also be other tools that can do such tasks for you. But I choose to write about FwTools as I am familiar with these tools from work. And another advantage is that FwTools is an open source project, so you can use the software for free.

Starting the FwTools shell

After you have installed FwTools you can best start the "FwTools shell". The installer should have placed a shortcut for this shell in your start menu. When you use this special shell, you are sure that the path is set correctly for all tools of the toolkit.

A very useful command is the gdalinfo command. When you use this on your image file, it will show all the information stored in the file. So this allows you to see if some geo information is already stored in your image.

 gdalinfo myfile.tif

This is an example of the output you can get when using gdalinfo on your image file:

 Driver: GTiff/GeoTIFF
 Size is 1600, 1200
 Coordinate System is:
 GEOGCS["WGS 84",
     DATUM["WGS_1984",
         SPHEROID["WGS 84",6378137,298.2572235630016,
             AUTHORITY["EPSG","7030"]],
         AUTHORITY["EPSG","6326"]],
     PRIMEM["Greenwich",0],
     UNIT["degree",0.0174532925199433],
     AUTHORITY["EPSG","4326"]]
 Origin = (2.873697280883789,51.239551252582089)
 Pixel Size = (0.000042915344238,-0.000026909535546)
 Metadata:
   AREA_OR_POINT=Area
   TIFFTAG_SOFTWARE=Adobe Photoshop CS2 Windows
   TIFFTAG_DATETIME=2007:03:03 09:28:16
   TIFFTAG_XRESOLUTION=96
   TIFFTAG_YRESOLUTION=96
   TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
 Corner Coordinates:
 Upper Left  (   2.8736973,  51.2395513) (  2d52'25.31"E, 51d14'22.38"N)
 Lower Left  (   2.8736973,  51.2072598) (  2d52'25.31"E, 51d12'26.14"N)
 Upper Right (   2.9423618,  51.2395513) (  2d56'32.50"E, 51d14'22.38"N)
 Lower Right (   2.9423618,  51.2072598) (  2d56'32.50"E, 51d12'26.14"N)
 Center      (   2.9080296,  51.2234055) (  2d54'28.91"E, 51d13'24.26"N)
 Band 1 Block=1600x5 Type=Byte, ColorInterp=Red
 Band 2 Block=1600x5 Type=Byte, ColorInterp=Green
 Band 3 Block=1600x5 Type=Byte, ColorInterp=Blue

Adding positional information to an image

One of the most common tasks will be to add position information to an image and thus creating a GeoTIFF file in that way. Let's assume you have the following information about your image:

 [GEOGRAPHIC]
 North=51.2395125258209
 South=51.20725980992728
 West=2.873697280883789
 East=2.942361831665039

To add this information to you image, you need to use the following command:

 gdal_translate -a_srs "+proj=latlong +datum=WGS84" -of GTiff
   -co "INTERLEAVE=PIXEL" -a_ullr 2.873697280883789 51.23955125258209
   2.942361831665039 51.20725980992728 myfile.jpg myfile.tif

The INTERLEAVE=PIXEL option is required to make the GeoTIFF in a format that resample can process. By default FwTools makes them in a band interleaved format, but resample can not read those.

For the input image you can use many different formats, the GDAL tools can read most common image formats. For the output file we will select GeoTIFF of course in this case.