tags:

views:

204

answers:

2

OK, so I have a jpeg and a bunch of ground control points (x/y pixels and corresponding lat/lon references).

I'd like to generate a .wld world file to accompany the jpeg, from the command line. My coordinate system is Google Maps, i.e. EPSG:900913.

I know that I can use gdal_transform to generate a .vrt given the gcps, but what I need is a .wld file. (Not really clear on the difference, but that's definitely what I need!)

Anyone have any idea how to do this?

Thanks Richard

A: 

A world file is basically a 6 line ascii text file determining your georeferencing. If you have a set of GCPs, you'll need to map them (using some tool like gdal) to a single affine transform.

I don't believe the gdal command line utilities give you the ability to just directly make a world file, although some drivers within GDAL will do this for you when you write an image if you set WORLDFILE=yes in the driver. You'll have to check the driver for your specific format to see if it supports this.

If it does not, though, you can do this easily by hand. Just make the .VRT file using the GCPs, and look at it in a text editor. It will have a section like this:

<GeoTransform>440720.0,  60,  0.0,  3751320.0,  0.0, -60.0</GeoTransform>

This "GeoTransform" is the affine transform used by a world file. All you need to do is make an ascii file that puts that with one value per line, like so:

60
0.0
0.0
-60.0
440720.0
3751320.0

That will be a valid .WLD file for your application.

FYI - The 6 numbers are the x pixel size, y shift per x value, x shift per y pixel, x origin, then y origin. (The shifts provide rotation/shearing capabilities in the affine transform. Typically, they'll be 0/0, since you normally want orthorectified imagery).

For details, see Wikipedia's entry on Worldfiles.

Reed Copsey
Superb answer, thank you :)
Richard
A: 

There is Python script gcps2wld.py in GDAL repository which translates the set of GCPs on a file into first order approximation in world file format.

I would add to Reed's answer that it's possible to give GCPs as command line parameters to gdal_translate:

gdal_translate -gcp 1 2 3 4 -gcp 6 7 8 9 [-gcp ...] -of GTiff inp.img out.tif
mloskot