# How to calculate "real" parameters from affine transformation

## Introduction

This page discusses how to compute physically significant parameters from an arbitrary linear transformation. The reverse process, calculating the affine parameters from the physically significant parameters, is articulated on another wiki page. The model used to describe how the raster maps onto real world coordinates is illustrated in the following figure:

This model contains all of the parameters except for translation. Translation may be added in after the coordinates have been scaled, rotated and sheared. The above illustration contains the physically significant parameters which will be calculated by this method. These are: θ_{i}, θ_{ij}, and the pixel size along the **i _{b}** and

**j**basis vectors.

_{b}The inputs to this method are the four non-translation (non-offset) parameters of a linear transform. These are shown below:

Although these parameters have "common names" within the GIS community, the names are both lengthy and misleading. Within the context of this page, the coefficients o_{11}, o_{12}, o_{21}, and o_{22} will be used.

This page is divided into sections. Each section describes the computation of one physically significant parameter.

## Pixel size in the **i** direction

To calculate the pixel size in the **i** direction, the **i** unit vector is projected using the given transform. This gives the basis vector **i _{b}**, the magnitude of which is the pixel size. The basis vector is expressed as follows:

The pixel size is then calculated as follows:

## Pixel size in the **j** direction

The pixel size in the **j** direction is computed in a manner similar to the pixel size in the **i** direction. The only difference is that the **j** unit vector is used in place of the **i** unit vector. This gives the basis vector **j _{b}**, the magnitude of which is the pixel size. The basis vector is expressed as follows:

The pixel size is then calculated as follows:

## Rotation

The grid is rotated by the angle θ_{i}. This is the angle between the **x** axis of the reference frame and the **i _{b}** basis vector. The angle θ

_{i}is considered positive in the clockwise direction, for consistency with compass headings. The calculation of θ

_{i}is a two-step process: first the magnitude is calculated, then the sign is determined. Both steps involve using the dot product to determine the angle between θ

_{i}and one of the axes of the target coordinate system (either the

**x**axis or the

**y**axis. The equations in this section refer to the angles and vectors defined in the following figure:

The first step is to calculate the magnitude of the angle between **i _{b}** and the x axis. This is the magnitude of θ

_{i}.

The angle θ_{i} is defined as the angle *from* the **x** axis *to* **i _{b}**. It is positive in the clockwise direction. In the situation described in the above figure, this means that θ

_{i}is negative if

**i**is above the

_{b}**x**axis, and positive if below. We determine whether

**i**is above or below the

_{b}**x**axis by finding the angle between

**i**and the

_{b}**y**axis. If

**i**and the

_{b}**y**axis are separated by less than 90 degrees,

**i**is above the

_{b}**x**axis, otherwise it is below.

So, if θ_{test} is less than 90, θ_{i} = - abs(θ_{i}). Otherwise, θ_{i} = abs(θ_{i}).

## Basis vector separation angle

In this section, the method to calculate θ_{ij} is presented. This is similar to the method for the calculation of θ_{i}, but it is accomplished with respect to the rotated reference frame of **i _{b}** and

**i**instead of the x and y axes. The figure which represents this setup is as follows:

_{bp}
The first step is to calculate the magnitude of θ_{ij}, the angle between **i _{b}** and

**j**.

_{b}
Next, we need to determine the sign of θ_{ij} in a manner similar to how the sign for θ_{i} was determined. The angle θ_{ij} always represents the angle *from* **i _{b}**

*to*

**j**, and is positive counterclockwise for consistency with a right-handed coordinate system. To do this, we first need to calculate

_{b}**i**, which is perpendicular to

_{bp}**i**and forms a right-hand coordinate system with

_{b}**i**. Observe that

_{b}**i**is

_{bp}**i**after a 90 degree counterclockwise rotation.

_{b}
Now we can determine the size of the angle between **j _{b}** and

**i**. In this situation, any angle less than 90 degrees means that

_{bp}**j**is on the same side of

_{b}**i**as

_{b}**i**. An angle more than 90 degrees means it lies on the opposite side.

_{bp}
So, if θ_{test} is more than 90 degrees, θ_{ij} = - abs(θ_{ij}). Otherwise, θ_{ij} = abs(θ_{ij}).

If θ_{ij} has any value other than +-90 degrees, the basis vectors are not orthogonal and the transformed pixels are diamond shaped. Probably the most common value for θ_{ij} is -90 degrees, which indicates that the transform "flips" the **j** axis.

## Summary

The method presented here performs calculations in the coordinate system used by the geocoordinates. All of the parameters calculated by this method are tied to the same SRID referenced by the transform **O**. It is assumed that the x and y axes of the geospatial coordinate system are orthogonal.

## See also

- Wikipedia article on the dot product.
- Wikipedia article on coordinate systems.
- Wikipedia article on the world file.
- How to calculate a transform based on physically significant parameters.

### Attachments (13)

- geotransform.png (2.1 KB) - added by 10 years ago.
- model.png (5.5 KB) - added by 10 years ago.
- basisvector_i.png (2.0 KB) - added by 10 years ago.
- basisvectormag_i.png (974 bytes) - added by 10 years ago.
- basisvector_j.png (2.1 KB) - added by 10 years ago.
- basisvectormag_j.png (1019 bytes) - added by 10 years ago.
- calc_theta_i.png (6.2 KB) - added by 10 years ago.
- thetamag_i.png (4.3 KB) - added by 10 years ago.
- thetatest_i.png (4.6 KB) - added by 10 years ago.
- calc_theta_ij.png (7.1 KB) - added by 10 years ago.
- basisvector_ip.png (5.0 KB) - added by 10 years ago.
- thetamag_ij.png (3.4 KB) - added by 10 years ago.
- thetatest_ij.png (3.5 KB) - added by 10 years ago.

Download all attachments as: .zip