Skip to content
Advertisement

How do I change a raster’s geotransform with GDAL?

I’m trying to use GDAL to set the geotransform of a new raster that I’ve created by following the steps outlined in the GDAL API Tutorial.

# create the new dataset
driver = gdal.GetDriverByName('GTiff')
dataset = driver.Create('test_gt.tif', 60, 60, 1, gdal.GDT_Float32)

# check the default geotransform
print dataset.GetGeoTransform()  # prints (0, 1, 0, 0, 0, 1)

# try to alter the geotransform and ensure that it has been set
dataset.SetGeoTransform([0,1,0,0,0,-1])
print dataset.GetGeoTransform()  # prints (0, 1, 0, 0, 0, -1)

dataset = None  # closes the dataset

# Try reopening the dataset now and see if the geotransform has been set.
ds = gdal.Open('test_gt.tif')
print ds.GetGeoTransform()  #prints (0, 1, 0, 0, 0, 1)

The dataset.SetGeoTransform() documentation says that this should set the affine transformation coefficients (which, according to the dataset.GetGeoTransform() documentation is set to [0, 1, 0, 0, 0, 1] by default), but as you can see from my above code, the changes don’t seem to actually take effect when I try to change them.

I’ve even tried flushing the new raster’s cache to disk by dataset.FlushCache(), but this doesn’t seem to save the changes either.

How can I have GDAL actually save the altered geotransform to disk?

I’m using GDAL version 1.6.3 installed from PyPI (via the command-line tool pip).

Advertisement

Answer

It turns out that this issue is version-specific. I upgraded to GDAL version 1.8.0 and the geotransform is set correctly now.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement