我正在尝试将表示 .tif 的栅格中的位置转换为相应的全局坐标。将整个数组转换为 tif 并将其加载到 QGIS 一切都很好,但是使用下面的单点计算方法有轻微的偏移(结果坐标中的东西向......
raster.tif 使用 ETRS 89 UTM Zone 32N
有没有人有想法?
from osgeo import ogr, gdal, osr
import numpy as np
raster = gdal.Open("rasters/raster.tif")
raster_array = np.array(raster.ReadAsArray())
def pixel2coord(x, y):
xoff, a, b, yoff, d, e = raster.GetGeoTransform()
xp = a * x + b * y + xoff
yp = d * x + e * y + yoff
return(xp, yp)
print(pixel2cood(500,598))
Run Code Online (Sandbox Code Playgroud)