从Python的栅格中提取旋转的矩形
我正在使用Python的GDAL与Geotiff Rasters合作。我使用以下代码从整个栅格中提取小矩形贴片:
data_file = gdal.Open("path/to/raster.tiff")
data = data_file.ReadAsArray(xoffset, yoffset, xsize, ysize)
如何将此代码更改为从栅格中提取旋转的矩形区域。例如,我希望能够从下面的红色区域中提取数据。
我希望重新采样并旋转红色区域,以便我可以简单地访问它Numpy数据阵列。
I'm using GDAL in Python to work with GeoTIFF rasters. I use the following code to extract small rectangular patches from the entire raster:
data_file = gdal.Open("path/to/raster.tiff")
data = data_file.ReadAsArray(xoffset, yoffset, xsize, ysize)
How could I change this code to extract rotated rectangular areas from the raster. For example, I would like to be able to extract data from the area shown in red below.
I'd like the red area to be resampled and rotated, so that I can access it as a simple numpy data array.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过遵循来创建解决方案。变换。
我的解决方案通过:
readasarray
读取完全包含红色区域的完整光栅的一部分;p0
,p1
,p2
在像素坐标中分别代表红色区域的上左上角,右上角和底部左下角;I created a solution to this by following this excellent post about how to implement affine transforms.
My solution works by:
ReadAsArray
to read a section of the full raster that fully contains the red area;p0
,p1
,p2
representing the top-left, top-right and bottom-left corners of the red area respectively in pixel coordinates;