1

我正在尝试通过遵循一些教程来学习 sentinelsat。部分代码是这样的。

import rasterio as rio
import geopandas as gpd

nReserve = gpd.read_file('NReserve/NaturalReserve_Polygon.shp')

nReserve_proj = nReserve.to_crs({'init': 'epsg:32633'})

with rio.open("RGB.tiff") as src:
    out_image, out_transform = rio.mask.mask(src, nReserve_proj.geometry,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 rio.open("RGB_masked.tif", "w", **out_meta) as dest:
    dest.write(out_image)

该行out_image, out_transform = rio.mask.mask(src, nReserve_proj.geometry,crop=True)给我错误。错误是这样的——

AttributeError                            Traceback (most recent call last)
<ipython-input-45-c1fc22fa2c5d> in <module>()
      2 
      3 with rio.open("RGB.tiff") as src:
----> 4     out_image, out_transform = rio.mask.mask(src, nReserve_proj.geometry,crop=True)
      5     out_meta = src.meta.copy()
      6     out_meta.update({"driver": "GTiff",

AttributeError: module 'rasterio' has no attribute 'mask'

但是 rasterio 的文档显示 rasterio.mask.mask() 存在。来自文档——

rasterio.mask.mask(dataset, shapes, all_touched=False, invert=False, nodata=None, filled=True, crop=False, pad=False, pad_width=0.5, indexes=None)

这里出了什么问题?我是新手,所以我不知道要检查什么。

4

0 回答 0