我正在尝试将表示.tif的光栅中的位置转换为相应的全局坐标。将整个阵列转换为tif并将其加载到QGIS中,一切都可以参考,但是使用下面的单点计算方法,会有一个轻微的偏移(在结果坐标中为东北偏东。。。。在
在光栅.tif使用ETRS 89 UTM区域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))
我认为问题可能是xoff和yoff包含最左上像素的左上角的坐标,您需要计算像素中心的坐标。在
没有理由手动执行此操作。你只需要安装python和mprasy库。即使图像有偏移/旋转光栅也会处理它。在
你只需:
这两个函数分别返回像素和坐标的元组。在
相关问题 更多 >
编程相关推荐