2

I have a set of topographic sheets in a form of non-georeferenced *.bmp rasters, and a shapefile representing footprints of those topographic sheets.

What I need to do is to using corresponding footprint coordinates.

All rasters have fixed dimensions of 7323 * 7323 pixels, and the actual grid that footprint represents is offset by 700 pixels from the edges of the raster.

How do I generate a world file (*.wld) for each .bmp raster in a set given pixel coordinates (raster dimensions and 700px grid offset is given) and cartographic coordinates from a corresponding footprint?

The thing similar to this is implemented in QGIS Georeferencer, but it requires manual input of GCP and doesn't provide batch mode.

  • QGIS Georeferencer is just a GUI around gdal_translate and gdalwarp. It can even generate a batch file for doing the same without GUI. Once you have understood the principles, you can batch process as many files as you want from command line. – AndreJ Jul 28 '17 at 15:55
  • @AndreJ thank you, but it seems that generating batch file for linear transformation is not available – Basile Aug 4 '17 at 14:14
2

The world file is just a text file renamed with the appropriate world file suffix. If you know the number of pixels, the size of each pixel on the ground, and the map coordinates of the center of the upper-left pixel you could calculate the offset and write the world files yourself in a text editor then rename the files to have the same name as the BMPs with the WLD suffix. Do you know the size of the pixel on the ground? Here is a Python script to create a wld file for every image in a directory. The values will need to be coded for your tiles.

from os import listdir    
inDir = r"Z:\GISpublic\GerryG\Shellfish_SalmonHatchery\DikeRepair2017\OutsideRepairs"
A = '100'
D = '0'
B = '0'
E = '100'
C = '100'
F = '345'
from os.path import isfile, join
onlyfiles = [f for f in listdir(inDir) if isfile(join(inDir, f))]
for file in onlyfiles:
    infile = inDir+"/"+file
    filename  = file.split(".")[0]
    outfile = inDir+"/"+filename+".wld"
    print outfile
    f = open(outfile, 'a')
    f.write(A+'\n'+D+'\n'+B+'\n'+E+'\n'+C+'\n'+F)
    f.close
  • I know that the size of the pixel on the ground can be calculated using topographic sheet's size in pixels and the unit size of a corresponding footprint. There are 2 problems though: 1) The upper-left pixel does not correspond to a footprint - the sheet frame a footprint corresponds to is offset by 700 px from a raster border (please see the question), so I have to account for that. 2) I want to perform the whole thing in a batch, because there are over 2000 rasters involved – Basile Jul 27 '17 at 23:06
  • 2
    OK, problem one sound like an arithmetic problem. Can you produce a table such that each row list the name of each image and the coordinates of the un-offset footprint? If so, populate the table with the corrections. Then read the table with Python and create the WLD files in batch. I have code that will get you started. Do you want that? – GBG Jul 27 '17 at 23:57
  • Yes, please. Still don't understand how to account for offset when creating a wld file that references plain top-left pixel. I think your code could help! – Basile Jul 28 '17 at 7:20
  • 2
    Off-Set? If you are in Euclidean space, and each image pixel represents 10 x10 meters on the ground, and you know that your image top left corner is 700 pixels right of true 0, 0, then subtract 7000 from 0. The coordinates for the top right pixel would be -7000, 0. I added the code to batch create a world file but the values of the world file are fixed. You need some kind of table-the top left coordinates of you reference grid for each image and some way to reference both the image and the grid. – GBG Jul 28 '17 at 14:20

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.