问题描述
我有一个 tiff 转换成一个数组 (498x401),我有一个数据框 (30x1) 收集不同点的坐标(tiff 和点坐标的 epsg 相同)。如何获取数组中像素的索引,对应于我的数据帧的点?
我尝试了以下代码,但输出不在我的数组中。代码中x3413和y3413分别对应dataframe中一个点的坐标。
from osgeo import osr,ogr,gdal
def world_to_pixel(geo_matrix,x,y):
"""
Uses a gdal geomatrix (gdal.GetGeoTransform()) to calculate
the pixel location of a geospatial coordinate
"""
ul_x= geo_matrix[0]
ul_y = geo_matrix[3]
x_dist = geo_matrix[1]
y_dist = geo_matrix[5]
pixel = int((x - ul_x) / x_dist)
line = -int((ul_y - y) / y_dist)
return pixel,line
# Extract target reference from the tiff file
ds = gdal.Open('myimage.tiff')
point = ogr.Geometry(ogr.wkbPoint)
point.AddPoint(x3413,y3413)
x,y = world_to_pixel(ds.GetGeoTransform(),point.GetX(),point.GetY())
print(x,y)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)