Transform a simple tiff into geotiff
By bruno combal on Monday, February 22 2010, 15:26 - Permalink
How to transform a simple tiff, or any image, into a georeferenced image, for example a geotiff. Quite simple with gdal_translate.
For this example, I took a random image, actually a photo of two elephants I took in Botswana. gdalinfo gives the following information about this image:
Driver: GTiff/GeoTIFF Files: IMG_8552.tif Size is 3456, 2304 Coordinate System is `' Metadata: TIFFTAG_DATETIME=2009:08:22 09:22:37 TIFFTAG_XRESOLUTION=72 TIFFTAG_YRESOLUTION=72 TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch) Image Structure Metadata: INTERLEAVE=PIXEL Corner Coordinates: Upper Left ( 0.0, 0.0) Lower Left ( 0.0, 2304.0) Upper Right ( 3456.0, 0.0) Lower Right ( 3456.0, 2304.0) Center ( 1728.0, 1152.0) Band 1 Block=3456x12 Type=Byte, ColorInterp=Red Band 2 Block=3456x12 Type=Byte, ColorInterp=Green Band 3 Block=3456x12 Type=Byte, ColorInterp=Blue Driver: GTiff/GeoTIFFFiles: IMG_8552.tifSize is 3456, 2304 Coordinate System is `'Metadata: TIFFTAG_DATETIME=2009:08:22 09:22:37 TIFFTAG_XRESOLUTION=72 TIFFTAG_YRESOLUTION=72 TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch) Image Structure Metadata: INTERLEAVE=PIXEL Corner Coordinates:Upper Left ( 0.0, 0.0) Lower Left ( 0.0, 2304.0) Upper Right ( 3456.0, 0.0) Lower Right ( 3456.0, 2304.0) Center ( 1728.0, 1152.0) Band 1 Block=3456x12 Type=Byte, ColorInterp=RedBand 2 Block=3456x12 Type=Byte, ColorInterp=GreenBand 3 Block=3456x12 Type=Byte, ColorInterp=Blue
As you can see there is absolutely no geographic information yet. Let’s says, even if it is absurd for this photo, that the corners are geolocated. gdal_translate options -a_ullr ulx uly lrx lry overrides the georeferenced bounds of the ouptut file and -a_srs srs_def overrides the projection for the output file.
Let’s give it a try:
gdal_translate -of gtiff -co "compress=LZW" -a_ullr -26 38 0 0 -a_srs "wgs84" IMG_8552.tif withCoordinates.tif
Now the result is georeferenced, as demonstrated by gdalinfo:
Driver: GTiff/GeoTIFF Files: withCoordinates.tif Size is 3456, 2304 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 = (-26.000000000000000,38.000000000000000) Pixel Size = (0.007523148148148,-0.016493055555556) Metadata: AREA_OR_POINT=Area TIFFTAG_DATETIME=2009:08:22 09:22:37 TIFFTAG_XRESOLUTION=72 TIFFTAG_YRESOLUTION=72 TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch) Image Structure Metadata: COMPRESSION=LZW INTERLEAVE=PIXEL Corner Coordinates: Upper Left ( -26.0000000, 38.0000000) ( 26d 0'0.00"W, 38d 0'0.00"N) Lower Left ( -26.0000000, 0.0000000) ( 26d 0'0.00"W, 0d 0'0.01"N) Upper Right ( 0.0000000, 38.0000000) ( 0d 0'0.01"E, 38d 0'0.00"N) Lower Right ( 0.0000000, 0.0000000) ( 0d 0'0.01"E, 0d 0'0.01"N) Center ( -13.0000000, 19.0000000) ( 13d 0'0.00"W, 19d 0'0.00"N) Band 1 Block=3456x1 Type=Byte, ColorInterp=Red Band 2 Block=3456x1 Type=Byte, ColorInterp=Green Band 3 Block=3456x1 Type=Byte, ColorInterp=Blue
and QuantumGis can easily use this image as geospatial raster: