从多个栅格输入中裁剪相同的地理多边形

时间:2019-08-21 21:16:07

标签: python geotiff rasterio

我正在尝试放置geotif栅格,以便可以提取相同区域的栅格数据,从而生成相同大小的输出图像。

该想法是要能够创建重叠的卫星照片的延时拍摄,其中一些照片仅包含重叠的分数,因此我需要对齐并裁剪/裁剪所有内容。

我当前正在使用rasterio,但是我没有被锁定使用它。 我正在尝试将以下两个栅格放置在位置:

因此它们将在同一坐标系中对齐。 想法是获取固定大小的输出,其中仅获取输入栅格中落在固定大小区域内的像素。

该坐标系是WGS 84 / UTM区域32N(EPSG:32632)。

安装依赖项:

pip install rasterio, numpy, pillow

示例:

import rasterio
from shapely.geometry.polygon import Polygon
from rasterio.mask import mask
from rasterio.plot import reshape_as_image
from PIL import Image


coords = [(331500,6171471),(480444,6171471), (480444,6320415),(331500,6320415)]
copenhagen_poly = Polygon(coords)

img_1 = rasterio.open('1_out.tif')
cropped_img_1, out_transform = mask(img_1, shapes=[copenhagen_poly], crop=True)
img_1 = reshape_as_image(img_1)
img_1 = Image.fromarray(img_1)

img_2 = rasterio.open('1_out.tif')
cropped_img_2, out_transform = mask(img_2, shapes=[copenhagen_poly], crop=True)
img_2 = reshape_as_image(img_2)
img_2 = Image.fromarray(img_2)

assert img_1.size, img_2.size == ((1803, 1997), (1948, 2000))

您会看到大小不匹配,这意味着我无法将完全相同的多边形(无论是否包含数据)提取到固定大小的结果图像中。

0 个答案:

没有答案