I have set of referenced rasters (.tif), which need to be tiled - but each of them need to be rotated by a certain degree before that using python (gdal mainly as other routines use it as well). In QGIS, for example, I can achieve the right view by changing map rotation value at the bottom right corner of the screen - it does exactly what i want, but does not affect tiling process in any way and can't be done outside of QGIS interface, which is important too. Initial raster view The intended way

While using North Pole Azimuthal projection (EPSG:102016) I tried to define custom CRS similar to it, but had no sucess as +alpha and +gamma parameters work only with +omerc projections.

I would be very grateful for pointing me in the right direction. Should i use custom wkt-defined CRS-es or, perhaps, in gdal tiling instrument there is some built-in way for rotating an image..?

P.S. Using azimuthal projection for tiling is kind of weird but it has its purpose. Thanks in advance for your help!

UPDATE: Seems like rotation can be performed by changing affine parameters via gdal.SetGeoTransform. However with formulae provided by @MortenSickel i got following result (1 is raster before changing affines, 2 - after). Btw the order of parameters is different in gdal compared to esri world file and that can lead to errors, but i double-checked that. update

  • What kind of format are the rasters? If there are tif /tfw rasters, you may be able to manipulate the tfw – MortenSickel Mar 9 at 16:09
  • .tif - edited the question – D.Moiseev Mar 9 at 16:17

What might work is to rotate the raster in qgis and then export it. That would by far be the easiest.

If the tif file is stored with a tfw world file, you should be able to rotate the raster by editing the tfw file. The format is relatively simple, e.g. https://en.wikipedia.org/wiki/World_file.

I would guess your tfw file looks something like


Where the lines are (copied from the above mentioned wikipedia page)

Line 1: A: x-component of the pixel width (x-scale)
Line 2: D: y-component of the pixel width (y-skew)
Line 3: B: x-component of the pixel height (x-skew)
Line 4: E: y-component of the pixel height (y-scale), typically negative
Line 5: C: x-coordinate of the center of the original image's upper left pixel transformed to the map
Line 6: F: y-coordinate of the center of the original image's upper left pixel transformed to the map

So if my math serves me right, to rotate the raster n degrees, you would make your lines


If you have the file raster.tif and raster.tfw, rename both of them to e.g. raster_rotate.tif and raster_rotate.tfw and edit the new .tfw-file.

I have edited tfw files a few times, but just to move the raster around or change the resolution, so this is just something I know should be working, but it may be more difficult

If your tif-file is without a .tfw file, the same information is stored as field within the tif-file. To get an editable .tfw-file run

gdal_translate -of GTiff -co tfw=yes infile.tif outfile.tif

This will create the outfile.tfw. To be able to get any effect of this file, you need to open the outfile.tfw in an image editor that can or will delete the attributes. (I tested it in gimp and exported the file as tif, selected the advanded drop down and unchecked all meta data)

Hope this helps, but also hope there is an easier way of doing it...

Hope this helps.

| improve this answer | |
  • i will check it asap. Thanks! – D.Moiseev Mar 9 at 20:04
  • Updated the question - changing affines works, but smth is still off. I couldn't really get these formulae myself, so can't check if there are any errors in them – D.Moiseev Mar 11 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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