使用shapefile剪辑或遮罩多波段图像

问题描述

下面的代码允许用户使用简单的多边形shapefile剪切图像(1个带)。但是,即使我尝试了几种变体,也无法将其应用于由多个波段组成的图像。我想做的是读取具有多个条带的Geotiff图像并将其全部裁剪,而无需将它们分成不同的图像。

from Rasterio.mask import mask
import geopandas as gpd

img = Rasterio.open("..\Image.tiff")
aoi = gpd.read_file("..\polyGON.shp")
geometry = aoi["geometry"]
clipImg,clipImg_Transform = mask(img,geometry,crop=True,invert=False)
clipImg_Meta = img.Meta.copy()
clipImg_Meta.update({"driver": "GTiff","height": clipImg.shape[1],"width": clipImg.shape[2],"transform": clipImg_Transform})

解决方法

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

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

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