[gdal-dev] python script to generate world files

Matt Wilkie matt.wilkie at gov.yk.ca
Mon Sep 12 20:28:22 EDT 2011


Hi Folks,

I've built a small gdal python script which builds world files for any 
supported georeferenced raster (I think). The full code is here: 
|gdal-makeworld.py| 
<http://code.google.com/p/maphew/source/browse/gis/o4w_extras/bin/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
     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 */
'''

|

Any feedback on the program's (in)correctness is appreciated. ||(I love 
python. It makes me feel so empowered to be able to accomplish stuff 
like this, even though I only have a blurred glimpses of understanding 
of programming and the like. :-)
||
Thank you Mike Toews for pointing me 
<http://gis.stackexchange.com/questions/14545/how-to-generate-world-files-for-raster-x> 
in the right direction, and additional thanks to Schuyler Erle for 
writing gdalcopyproj.py which I used as a starting point.

-- 
matt wilkie
--------------------------------------------
Geomatics Analyst
Information Management and Technology
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
867-667-8133 Tel * 867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------



More information about the gdal-dev mailing list