我希望能够使用流域作为边界来剪切栅格数据。我已经尝试使用Fiona和Rasterio进行了实验。
以下是我的代码:
以下是我的代码:
import fiona
import rasterio
from rasterio.rio.clip import clip
with fiona.open("oreto_bacino2.shp", "r") as shapefile:
geoms = [feature["geometry"] for feature in shapefile]
with rasterio.open("cn.asc") as src:
out_image, out_transform = clip (geoms, src, crop=True)
out_meta = src.meta.copy()
out_meta.update({
"driver": "GTiff",
"height": out_image.shape[1],
"width": out_image.shape[2],
"transform": out_transform
})
with rasterio.open("cn_masked.tif", "w", **out_meta) as dest:
dest.write(out_image)
这是我得到的错误:
complete_var = '_%s_COMPLETE' % (prog_name.replace('-', '_')).upper()
出现了以下错误:
AttributeError: 'rasterio._io.RasterReader'对象没有'replace'属性
有人知道正确的操作方式吗?