[Geotiff] Affine Transformation

Frank Warmerdam warmerdam at pobox.com
Sat Mar 14 22:36:26 EST 2009


Gianni Rossi wrote:
> I’m new both to this mail-list and to GeoTIFF too.
> 
> Nevertheless, I’m developing a Cad application which allows the user to 
> pick a desired number of points in a TIFF raster image (thus the 
> application retrieves their raster coordinates) and inputs their 
> corresponding model coordinates. Then the application performs an affine 
> transformation between the two systems and calculates the 4 parameters: 
> X translation, Y translation, scaling factor, rotation angle.
> 
> So my question is: how do I store this georeferencing data into the 
> original TIFF file so that it becomes a GeoTIFF file?
> 
> Looking at some documentation, it seems that ModelTransformationTag 
> would do the case, but unfortunately I could not find specification on 
> how to transform my (affine transformation) parameters into its arguments.

Gianni,

I think you would want to write things something like:

	    double	adfMatrix[16];
	
	    memset(adfMatrix,0,sizeof(double) * 16);
	
	    adfMatrix[0] = PixelSize * cos(Rotation);
	    adfMatrix[1] = PixelSize * sin(Rotation);
	    adfMatrix[3] = XOrigin;
	    adfMatrix[4] = PixelSize * sin(Rotation);
	    adfMatrix[5] = -1.0 * PixelSize * cos(Rotation);
	    adfMatrix[7] = YOrigin;
	    adfMatrix[15] = 1.0;
	
             TIFFSetField( hTIFF, TIFFTAG_GEOTRANSMATRIX, 16, adfMatrix );


The XOrigin and YOrigin are the top left corner of the image, the
PixelSize is the width/height of a pixel in geo units, and the Rotation
is the rotation angle in radians (if using the C sin/cos functions)
clockwise from straight up.

I may have made a few mistakes but the gist of the solution is here.
The worldfile coefficients are computed similarly though the ordering
is presumably different.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the Geotiff mailing list