仅获取与平铺窗口相交的多边形

问题描述

让我解释一下我的问题。我有以下代码行得到的边界框坐标:

bounds_coords = trees_Boxes['geometry'].bounds

我找到了以下脚本来创建具有大图像的图块:

import os
from itertools import product
import Rasterio as rio
from Rasterio import windows

in_path = '/content/drive/My Drive/DS_ML-DL_Projects/Tree_Grand_Forks/'
input_filename = 'Grand_Fork_42cm_RGBN.tif'

out_path = '/content/drive/My Drive/DS_ML-DL_Projects/Tree_Grand_Forks/Tiles_500/'
output_filename = 'tile_{}-{}.tif'

def get_tiles(ds,width=500,height=500):
    nols,nrows = ds.Meta['width'],ds.Meta['height']
    offsets = product(range(0,nols,width),range(0,nrows,height))
    big_window = windows.Window(col_off=0,row_off=0,width=nols,height=nrows)
    for col_off,row_off in  offsets:
       window =windows.Window(col_off=col_off,row_off=row_off,width=width,height=height).intersection(big_window)
        transform = windows.transform(window,ds.transform)
        yield window,transform


with rio.open(os.path.join(in_path,input_filename)) as inds:
    tile_width,tile_height = 500,500

    Meta = inds.Meta.copy()

    for window,transform in get_tiles(inds):
        print(window)
        Meta['transform'] = transform
        Meta['width'],Meta['height'] = window.width,window.height
        outpath = os.path.join(out_path,output_filename.format(int(window.col_off),int(window.row_off)))
        with rio.open(outpath,'w',**Meta) as outds:
            outds.write(inds.read(window=window))

我想要的是在最后一个for循环中构建代码,以便我可以获得每个图块中包含的所有边界框的列表。

最终的目标是为每行创建一个DataFrame:图像图块的名称一个多边形坐标(因此,我拥有的行数与一幅图像的边界框一样多)。

我该怎么做?我在寻找解决方案,但是我在Python编程领域还是一个新手。

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)