How to generate world files for raster X?

If you're using a recent build of QGIS, you may already have access to the Extract Projection tool mentioned here.

From the article: "What this lets you do is to find out what projection your rasters are in. It then exports this to a .WLD file. It also allows you to create .PRJ files. If you have GDAL Tools installed (and activated), you'll find this new tool under Raster > Projections > Extract Projection."

It includes a batch processing option as well, which is great for your purposes.


Sparked by Mike Toews pointer to GetGeoTransform, I managed to create a small gdal python script which builds world files for any supported georeferenced raster (I think). The full code is here: gdal-makeworld.py. The essential bits are:

geotransform = dataset.GetGeoTransform()

if geotransform is not None:
    x, x_size, x_rot, y, y_rot, y_size = geotransform
    # correct for centre vs corner of pixel
    x = x_size/2+x
    y = y_size/2+y
    world_file.write('%s\n' % x_size)
    world_file.write('%s\n' % x_rot)
    world_file.write('%s\n' % y_rot)
    world_file.write('%s\n' % y_size)
    world_file.write('%s\n' % x)
    world_file.write('%s\n' % y)
    world_file.close()

''' geotransform tuple key:
    [0] /* top left x */
    [1] /* w-e pixel resolution */
    [2] /* rotation, 0 if image is "north up" */
    [3] /* top left y */
    [4] /* rotation, 0 if image is "north up" */
    [5] /* n-s pixel resolution */
'''

Additional thanks to Schuyler Erle for writing gdalcopyproj.py which I used as a starting point.

Hat tip @AlisterH for "correct for centre vs corner of pixel", 2019-05-30