如何使用GDAL更改栅格的地理变换? [英] How do I change a raster's geotransform with GDAL?
问题描述
我正在尝试使用GDAL,按照 GDAL API教程.
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)
dataset.SetGeoTransform()文档说,这应该设置仿射变换系数(根据dataset.GetGeoTransform()
文档默认情况下将其设置为[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.
我什至尝试通过dataset.FlushCache()
将新栅格的缓存刷新到磁盘,但这似乎也无法保存更改.
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.
如何让GDAL实际上将更改后的地理转换保存到磁盘上?
How can I have GDAL actually save the altered geotransform to disk?
我正在使用从PyPI安装的GDAL版本1.6.3(通过命令行工具pip
).
I'm using GDAL version 1.6.3 installed from PyPI (via the command-line tool pip
).
推荐答案
事实证明,此问题是特定于版本的.我已升级到GDAL 1.8.0版,现在正确设置了geotransform.
It turns out that this issue is version-specific. I upgraded to GDAL version 1.8.0 and the geotransform is set correctly now.
这篇关于如何使用GDAL更改栅格的地理变换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!