如何解决仅获取与平铺窗口相交的多边形
让我解释一下我的问题。我有以下代码行得到的边界框坐标:
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 举报,一经查实,本站将立刻删除。