从Python的栅格中提取旋转的矩形

发布于 2025-02-12 12:04:05 字数 508 浏览 0 评论 0原文

我正在使用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.

enter image description here

I'd like the red area to be resampled and rotated, so that I can access it as a simple numpy data array.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

腻橙味 2025-02-19 12:04:05

我通过遵循来创建解决方案。变换。

我的解决方案通过:

  1. 使用readasarray读取完全包含红色区域的完整光栅的一部分;
  2. 识别点p0p1p2在像素坐标中分别代表红色区域的上左上角,右上角和底部左下角;
  3. 如链接中所述实现算法以计算仿射变换,使我独自一人旋转到水平位置。

I created a solution to this by following this excellent post about how to implement affine transforms.

My solution works by:

  1. Using ReadAsArray to read a section of the full raster that fully contains the red area;
  2. Identifying points p0, p1, p2 representing the top-left, top-right and bottom-left corners of the red area respectively in pixel coordinates;
  3. Implementing the algorithm as described in the link to compute the affine transform, leaving me with the red area on its own, rotated into a horizontal position.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文