从rasterio数据源获取坐标数组

时间:2019-12-10 17:26:45

标签: python numpy raster rasterio

我想使用特定大小的pyresample将矢量数据重新采样到栅格图像,但是对于如何使用rasterio从栅格获取x和y坐标数组感到困惑。

如果我有一个res=1000形状的1000米(273, 255)光栅图像,其边框为:

from collections import namedtuple
BoundingBox = namedtuple('BoundingBox', ('left', 'bottom', 'right', 'top'))
bounds = BoundingBox(-1395000.0,2198000.0,-1140000.0,2471000.0)

我认为我可以使用np.arangenp.meshgrid获得坐标数组:

res = 1000
min_E, max_E = bounds.left, bounds.right
min_N, max_N = bounds.bottom, bounds.left
xx, yy = np.meshgrid(np.arange(min_E, max_E, res), np.arange(min_N, max_N, res))

xxyy的形状均为(273, 255),这似乎是正确的。当我检查xxyy的范围是否返回与bounds中相同的值时,我感到困惑。

print('Top of Grid', yy.max())
print('Top bounding coordiante:', bounds.top, )
print('Are top Coordinates equal:', bounds.top == yy.max())
print('Bottom of Grid', yy.min(),)
print('Bottom bounding coordiante',bounds.bottom,)
print('Are bottom cordinates equal', bounds.bottom == yy.min())
print('Left of Grid', xx.min(),)
print('Left bounding coordiante', bounds.left,)
print('Are left coordinates equal', bounds.left == xx.min())
print('Right of Grid', xx.max(),)
print('Right bounding coordiante',bounds.right,)
print('Are right coordiantes equal', bounds.right == xx.max())

返回哪个:

Top of Grid 2470000.0
Top bounding coordinate: 2471000.0
Are top Coordinates equal: False
Bottom of Grid 2198000.0
Bottom bounding coordinate 2198000.0
Are bottom coordinates equal True
Left of Grid -1395000.0
Left bounding coordinate -1395000.0
Are left coordinates equal True
Right of Grid -1141000.0
Right bounding coordinate -1140000.0
Are right coordinates equal False

网格的底部和左侧均与输入范围匹配,但网格的顶部和右侧均比bound.topbounds.right小1000米。我知道np.arange会产生一系列值[开始,停止)。但是我似乎无法说服自己,坐标网格xxyy实际上代表了int输入栅格数据集的坐标。

有人能解释为什么吗?

使用以下方法构造仿射也是正确的吗?

affine = rasterio.Affine.from_gdal(xx.min(),res,0,yy.max()+1000,0,-res)

e设置为yy.max()+1000使我感到紧张,我做错了什么。

0 个答案:

没有答案