Monday 26 March 2018

raster - How to generate TFW files for a list of images?


I have a few digital images that are not georeferenced. E.g.:



Img01.tif  
Img02.tif
...
Img99.tif

On the other hand, I have a text file, which contains georeferencing information for these images. E.g., I have a file c:\tfws\list.txt which contains the following information:


Img01.tfw 0.25 0 0 - 0.25 456258,125 4569852,125  
Img02.tfw 0.25 0 0 - 0.25 456586,125 4570001,125
Img03.tfw 0.25 0 0 - 0.25 456952,125 4570300,125
...

Img99.tfw 0.25 0 0 - 0.25 458412,125 4575123,125

I need to generate a TFW file for each image in the text file. E.g. create a file named C:\tfws\img??.tfw containing the following information:


0.25  
0
0
-0.25
456258,125
4569852,125


Does anyone know of a tool able to generate these TFW files automatically?



Answer



It isn't nice code, but for your specific circumstance, here is some python that should save typing them out by hand:


f = open('list.txt', 'r')
lines = f.readlines()
for line in lines:
lineparts = line.split(' ')
outfile = open(lineparts[0], 'w')
for i in range(1, 4):
outfile.write(lineparts[i] + '\n')

outfile.write(lineparts[4] + lineparts[5] + '\n')
for i in range(6, 8):
outfile.write(lineparts[i] + '\n')

(real code would sanity check, but I assume you can check the results)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...