【发布时间】:2021-03-15 11:41:48
【问题描述】:
我正在尝试在 python、GDAl 和/或 QGIS 中以不同的量旋转 geotif,并保持地理参考信息相同。 有没有办法做到这一点?
【问题讨论】:
标签: python gdal qgis geotiff rasterio
我正在尝试在 python、GDAl 和/或 QGIS 中以不同的量旋转 geotif,并保持地理参考信息相同。 有没有办法做到这一点?
【问题讨论】:
标签: python gdal qgis geotiff rasterio
您可以通过modifying the GeoTransform 执行此操作。如果要“就地”修改 GDAL 图像(即不创建新图像),可以以读写模式打开它:
from osgeo import gdal
Image = gdal.Open('ImageName.tif', 1) # 1 = read-write, 0 = read-only
GeoTransform = Image.GetGeoTransform()
GeoTransform 是一个包含以下属性的元组: (UpperLeftX, PixelSizeX, RowRotation, UpperLeftY, ColRotation, -PixelSizeY)
元组在 Python 中是不可变的,因此要修改 GeoTransform,您必须将其转换为列表,然后在将其写入 GDAL 图像之前再次恢复为元组:
GeoTransform = list(GeoTransform)
GeoTransform[2] = 0.0 # set the new RowRotation here!
GeoTransform[-2] = 0.0 # set the new ColRotation here!
GeoTransform = tuple(GeoTransform)
Image.SetGeoTransform(GeoTransform) # write GeoTransform to image
del Image # close the dataset
【讨论】: