I'm trying to alter the metadata in a Geotiff header via a .tfw file. When I change Pixel Size in the .tfw file, that is reflected in GDALINFO how I would expect.

However, when I change the Origin Value in the tfw file, GDALINFO is not displaying exactly what I type in the .tfw file. It's displaying a long float value. I'm ok with having repeating zeros like the Pixel Size data but I can't have random numbers like the Origin value.

enter image description here

and when I run GDALINFO I get these results..

enter image description here

Any ideas why what I put in the .tfw file isn't displaying in GDALINFO.


I've tried using Python to resolve this issue but still not getting desired results.

from osgeo import gdal
from osgeo import gdalconst

tiff_path = r"E:\temp\fran\pizelsize\test.tif"

data2 = gdal.OpenShared(tiff_path, gdalconst.GA_Update)

geoTransform_tuple = data2.GetGeoTransform()
list_of_tuple = list(geoTransform_tuple)

for x in list_of_tuple:
    print x

print '\n'

origin_X = round(list_of_tuple[0], 3)
origin_Y = round(list_of_tuple[3], 3)
res_X = round(list_of_tuple[1], 4)
res_Y = round(list_of_tuple[5], 4)

list_of_tuple[0] = origin_X
list_of_tuple[3] = origin_Y
list_of_tuple[1] = res_X
list_of_tuple[5] = res_Y

for x in list_of_tuple:
    print x

data2 = None

I've tried setting everything to a float. I've tried using the Decimal module. I've tried converting to string then back to float. I get the desired result displayed in python. But when I try to write it to the tiff, only Pixel Size gets updated.

enter image description here

The second output is what I want in the tiff. But GDALINFO gives me this.

enter image description here

Pixel Size updated, Origin either not updated or calculated some other way.

  • 2
    This belongs to World File trivia. Origin that is used in TFW is placed at the middle of the top-left pixel while GDAL puts it into the top-left corner of the top-left pixel. Therefore you will get 15 cm shift and a rather small rounding error. No need to worry. – user30184 May 18 '17 at 14:53
  • Interesting thanks for the response. I'm really just trying to change that Origin value in GDALINFO. I thought going the .TFW route would be simple. I've tried a lot of different things including updating the geotransform values via Python but I never get a clean result. It's always that floating number. – fpolig01 May 18 '17 at 14:57
  • Then the value you want probably can't be represented exactly by binary numbers. – mkennedy May 19 '17 at 17:11
  • If that's the case, I would also expect the Pixel Size field to behave the same way. I can get the Pixel Size to update how I want. It just adds a bunch of zeros on the end which is fine. – fpolig01 May 19 '17 at 17:22
  • Pixel size is used as is. Origin is computed as (world file originX) - (pixel size/2) and (world file originY) + (pixel size/2). If you need to set the origin exactly don't use TFW but set it directly to GDAL geotransform with Python or something gdal.org/gdal_tutorial.html. You wrote you could not make it work so please show your python code, But what issues do you have now? The origin value is not "random". Doesn't rounding to a bit less desimal places work for you? – user30184 May 21 '17 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.