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

你。 提交于 2020-01-05 02:58:27

问题


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).


回答1:


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



来源:https://stackoverflow.com/questions/9726637/how-do-i-change-a-rasters-geotransform-with-gdal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!