Geotiff旋转Python/GDAL/QGIS

2024-05-21 02:13:45 发布

您现在位置:Python中文网/ 问答频道 /正文

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


Tags: 信息数量地理gdal办法qgisgeotifs
1条回答
网友
1楼 · 发布于 2024-05-21 02:13:45

您可以通过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

相关问题 更多 >