[gdal-dev] Affine transform: Practical uses of x-skew and y-skew

Mike Taves mwtoews at gmail.com
Sun May 3 16:17:52 PDT 2020

```On Sat, 2 May 2020 at 08:01, Craig Delancy
<cdelancy at blackfangtechnologies.com> wrote:
> I am trying to explain to a colleague how the affine transform maps image coordinates onto a projection system.
> Specifically, I am trying to explain how mathematically speaking, any parallelogram section of the coordinate system can be represented by the rectangular image.
> After a bit of searching, I wasnâ€™t able to find an example dataset to illustrate this.
>
> I am wondering, is there any practical use for this?
> Does anyone have an example dataset they would be willing to send/show me?

The terms "x-skew" and "y-skew" are a bit misleading, as these are two
coefficients in a matrix. Possibly a better label is "shear", since
they are coefficients that relate to two dimensions, which are
normally zero if the raster is aligned to the coordinate system. You
can see the maths and visualise some of the transforms with Shapely
docs:

And you can assemble some real-world affine transforms for GDAL using
the Affine Python package:

from affine import Affine
a = Affine.from_gdal(101985.0, 300.0, 0.0, 826915.0, 0.0, -300.0)
print(a)
# | 300.00, 0.00, 101985.00|
# | 0.00,-300.00, 826915.00|
# | 0.00, 0.00, 1.00|
ash = a * Affine.shear(20)
print(ash)
# | 300.00, 109.19, 101985.00|
# | 0.00,-300.00, 826915.00|
# | 0.00, 0.00, 1.00|
print(ash.to_gdal())
# (101985.0, 300.0, 109.1910702798607, 826915.0, 0.0, -300.0)

As you can see there are from_gdal and to_gdal methods to re-arrange
the order of coefficients for GDAL's get/set GeoTransform methods.
Shearing the geotransform by 20 degrees along the x-axis only modifies
one coefficient in the matrix. Obviously there is plenty of further
reading on Wikipedia and other free sources.
```