8

Given a list of georeferenced rasters, about a hundred, what is the simplest method to generate world files for each?

In this case the source rasters are either geotiff with embedded georeferencing or .BIL with accompanying .PRJ, but the ideal solution shouldn't care what the format is. I'm hoping to avoid duplicating data.

I have at my disposal Arcgis 10 (Arcinfo & Spatial Analyst), GDAL Utilities (gdal v1.8.0), and Quantum GIS 1.8.

3
  • generating world files will not always ensure that a software can/does read the world file for georeferencing. Geotiff is what I have had the most luck with in different software.
    – Brad Nesom
    Sep 12, 2011 at 17:29
  • are you trying to read EHdr format?? gdal.org/frmt_various.html
    – falcacibar
    Sep 12, 2011 at 18:41
  • 1
    the software I'm preparing these for doesn't understand embedded georeferencing or external .prj (proj4 or wkt) files. It only looks at .wld (or .blw, .jpw,... etc.). Sep 12, 2011 at 19:05

2 Answers 2

12

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.

1
  • so if I'd waited I day I could have saved myself a couple hours of work! but I wouldn't have learned anything, so I'll call it even. ;-) From reading the commit log, in addition to all the user interface goodness the what this qgis tool does better than mine is handle unicode filenames and writes an external esri-style .prj file. It doesn't do is follow the convention of naming the extension after the input, e.g. for a jpeg it writes .wld rather than .jgw, which may or may not matter to others. Accepting this as the correct answer even though I didn't use it, as it the most complete solution. Sep 13, 2011 at 16:19
7

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

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.