I want to generate a raster which is rotated with respect to its coordinate system. As I understand this requires modifying the geotransform array. I have not been able to find much information about this (though I did find a related SE question in Rotating rasters using GDAL Geotransform (and ArcGIS Desktop), and a thread on the GDAL-dev mailing list here, apparently started by the same person).

Most sites seem to only provide information on the structure of the unrotated geotransform. Based on the linked post & mailing list thread, I understand that the rotated geotransform should have the following elements:

[0] x-coordinate of upper-left raster corner
[1] cos(θ) * x_resolution
[2] -sin(θ) * x_resolution
[3] y-coordinate of upper-left raster corner
[4] sin(θ) * y_resolution
[5] cos(θ) * y_resolution

However, I am not sure if this is correct.

I have tried using python to save a rotated raster using the above as a guideline for my geotransform, but the output is not what I expected. I defined my geotransform as:

# Define raster array to save
array = np.arange(0,25).reshape(5,5)

# Define rotation & geotransform
rot = rot*math.pi/180
gt = (0,math.cos(rot)*x_res, -math.sin(rot)*x_res, 0, math.sin(rot)*y_res, math.cos(rot)*y_res)

# Save raster
save_raster(outfile, array, srs, gt)

And got the following result:

rotated array

In a sense the raster has been 'rotated', but it appears my array has been resampled (which I do not want) while the raster cells are still aligned with the coordinate system x/y axes.

Am I just misunderstanding how the geotransform array works? Is there even a way to do what I am trying to do?

  • When you save the the image into a new file it is resampled to CRS axis oriented system. By the same the rotation elements get removed as you can see from a gdalinfo report. If you just attach the rotated geotransform into the original image no resampling happens. Then it is up to the using applications to rotate the image when it is shown for example on computer screen.
    – user30184
    Mar 17, 2018 at 8:35
  • Thanks for the advice; however, even when I open an existing file using GA_Update, the image is still resampled on setting a new geotransform. Is there a way to override this behavior?
    – corvus
    Mar 17, 2018 at 14:44
  • What do you await really? Rasters are rectangular and if you want to show the original image as rotated on a computer screen then there will appear no-data areas at each corner which must be filled with new pixels. Orientation of pixels remains horizontal-vertical because rotating the image does not rotate the screen. Perhaps an alternative way for visualizing the result could be not to rotate the image at all on screen but draw the South-North and East-West coordinate axes on top of the image as vectors which would then be more or less diagonal.
    – user30184
    Mar 20, 2018 at 12:46
  • My thought was that the raster cells themselves would be rotated within the coordinate reference system, i.e. the rows and columns would not be oriented in the same direction as the unit vectors of the coordinate system. However, maybe this is not possible?
    – corvus
    Mar 20, 2018 at 15:27
  • Parameters in geotransform are the same than in ESRI world file en.wikipedia.org/wiki/World_file. You can rotete the image without touching any pixel by writing a new world file. In the same way you should be able to just write the geotransform metadata into an image without warping it into a north-up raster as in stackoverflow.com/questions/9726637/….
    – user30184
    Mar 20, 2018 at 21:09

1 Answer 1


To my understanding this is actually an issue with QGIS, and there is an open issue related to providing better support for rotated rasters.

See also: https://github.com/qgis/QGIS/issues/22012

GDAL does consider the pixel grid as being truly rotated. The geotransform provides an affine transformation from image to map space, so if the geotransform describes a rotation then a grid in image space would obviously end up rotated in map space. The geotransform tutorial gives a good overview.

Both the unrotated pixels and the apparent resampling are display artifacts, and don't reflect the underlying data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.