External Classes

class affine.Affine[source]

Two dimensional affine transform for 2D linear mapping.


b, c, d, e, f (a,) –

Coefficients of an augmented affine transformation matrix

x’ | | a b c | | x |
y’ | = | d e f | | y |
1 | | 0 0 1 | | 1 |

a, b, and c are the elements of the first row of the matrix. d, e, and f are the elements of the second row.

a, b, c, d, e, f, g, h, i

The coefficients of the 3x3 augumented affine transformation matrix

x’ | | a b c | | x |
y’ | = | d e f | | y |
1 | | g h i | | 1 |

g, h, and i are always 0, 0, and 1.



The Affine package is derived from Casey Duncan's Planar package.
See the copyright statement below. Parallel lines are preserved by
these transforms. Affine transforms can perform any combination of
translations, scales/flips, shears, and rotations. Class methods
are provided to conveniently compose transforms from these
Internally the transform is stored as a 3x3 transformation matrix.
The transform may be constructed directly by specifying the first
two rows of matrix values as 6 floats. Since the matrix is an affine
transform, the last row is always ``(0, 0, 1)``.

multiplication of a transform and an (x, y) vector always

returns the column vector that is the matrix multiplication product
of the transform and (x, y) as a column vector, no matter which is
on the left or right side. This is obviously not the case for
matrices and vectors in general, but provides a convenience for
users of this class.
almost_equals(other, precision=1e-05)[source]

Compare transforms for approximate equality.


other (Affine) – Transform being compared.


True if absolute difference between each element of each respective transform matrix < self.precision.

property column_vectors

The values of the transform as three 2D column vectors

property determinant

The determinant of the transform matrix.

This value is equal to the area scaling factor when the transform is applied to a shape.

property eccentricity

The eccentricity of the affine transformation.

This value represents the eccentricity of an ellipse under this affine transformation.

Raises NotImplementedError for improper transformations.

classmethod from_gdal(c, a, b, f, d, e)[source]

Use same coefficient order as GDAL’s GetGeoTransform().


a, b, f, d, e (c,) – 6 floats ordered by GDAL.

Return type


classmethod identity()[source]

Return the identity transform.

Return type


property is_conformal

True if the transform is conformal.

i.e., if angles between points are preserved after applying the transform, within rounding limits. This implies that the transform has no effective shear.

property is_degenerate

True if this transform is degenerate.

Which means that it will collapse a shape to an effective area of zero. Degenerate transforms cannot be inverted.

property is_identity

True if this transform equals the identity matrix, within rounding limits.

property is_orthonormal

True if the transform is orthonormal.

Which means that the transform represents a rigid motion, which has no effective scaling or shear. Mathematically, this means that the axis vectors of the transform matrix are perpendicular and unit-length. Applying an orthonormal transform to a shape always results in a congruent shape.

property is_proper

True if this transform is proper.

Which means that it does not include reflection.

property is_rectilinear

True if the transform is rectilinear.

i.e., whether a shape would remain axis-aligned, within rounding limits, after applying the transform.


Transform a sequence of points or vectors in place.


seq – Mutable sequence of Vec2 to be transformed.


None, the input sequence is mutated in place.

classmethod permutation(*scaling)[source]

Create the permutation transform

For 2x2 matrices, there is only one permutation matrix that is not the identity.

Return type


classmethod rotation(angle, pivot=None)[source]

Create a rotation transform at the specified angle.

A pivot point other than the coordinate system origin may be optionally specified.

  • angle (float) – Rotation angle in degrees, counter-clockwise about the pivot point.

  • pivot (sequence) – Point to rotate about, if omitted the rotation is about the origin.

Return type


property rotation_angle

The rotation angle in degrees of the affine transformation.

This is the rotation angle in degrees of the affine transformation, assuming it is in the form M = R S, where R is a rotation and S is a scaling.

Raises NotImplementedError for improper transformations.

classmethod scale(*scaling)[source]

Create a scaling transform from a scalar or vector.


scaling (float or sequence) – The scaling factor. A scalar value will scale in both dimensions equally. A vector scaling value scales the dimensions independently.

Return type


classmethod shear(x_angle=0, y_angle=0)[source]

Create a shear transform along one or both axes.

  • x_angle (float) – Shear angle in degrees parallel to the x-axis.

  • y_angle (float) – Shear angle in degrees parallel to the y-axis.

Return type



Return same coefficient order as GDAL’s SetGeoTransform().

Return type


classmethod translation(xoff, yoff)[source]

Create a translation transform from an offset vector.

  • xoff (float) – Translation x offset.

  • yoff (float) – Translation y offset.

Return type


property xoff

Alias for ‘c’

property yoff

Alias for ‘f’