Geotiff旋转Python/GDAL/QGIS

Geotiff旋转Python/GDAL/QGIS,python,gdal,qgis,geotiff,rasterio,Python,Gdal,Qgis,Geotiff,Rasterio,我试图在python、GDAl和/或QGIS中按不同的数量旋转geotifs,并保持地理参考信息不变。 有什么方法可以做到这一点吗?你可以通过。如果要“就地”修改GDAL图像(即不创建新图像),可以在读写模式下打开该图像: from osgeo import gdal Image = gdal.Open('ImageName.tif', 1) # 1 = read-write, 0 = read-only GeoTransform = Image.GetGeoTransform() GeoT

我试图在python、GDAl和/或QGIS中按不同的数量旋转geotifs,并保持地理参考信息不变。 有什么方法可以做到这一点吗?

你可以通过。如果要“就地”修改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