我用的是Python;Python=v.3.6.13;里奥沙雷=v。0.4.0;光栅。1.10. 一切都在虚拟环境中
下面是我用来在光栅(例如马赛克)上显示矢量(aoi_形状文件)的代码:
import rioxarray as rxr
from rasterio.plot import show
from rasterio.plot import show_hist
from rasterio.mask import mask
from shapely.geometry import box
import geopandas as gpd
from fiona.crs import from_epsg
import seaborn as sns
from shapely.geometry import mapping
# Open example mosaic & AOI extent shapefile
example_mosaic = rxr.open_rasterio(r'C:\Users\Matthew\OneDrive\Land Suitability Model'
r'\Layers\Sentinel\Sentinel RST\mosaic_b8.tif')
aoi_shapefile = gpd.read_file(r'C:\Users\Matthew\OneDrive\Land Suitability Model'
r'\Layers\Sentinel\Sentinel RST\mask_proj.shp')
# Prettier plotting with seaborn
sns.set(font_scale=1.5)
# Overlay AOI & sentinel mosaics
f, ax = plt.subplots(figsize=(15, 10))
example_mosaic.plot.imshow(ax=ax)
aoi_shapefile.plot(ax=ax,alpha=.8)
ax.set(title="Mosaic Layer with Shapefile Overlayed")
plt.show()
尝试导入rioxarray时产生错误:
> --------------------------------------------------------------------------- AttributeError Traceback (most recent call
> last) <ipython-input-2-6111f71011c8> in <module>
> ----> 1 import rioxarray as rxr
> 2 from rasterio.plot import show
> 3 from rasterio.plot import show_hist
> 4 from rasterio.mask import mask
> 5 from shapely.geometry import box
>
> ~\anaconda3\envs\Raster
> Analysis\lib\site-packages\rioxarray\__init__.py in <module>
> 6 import rioxarray.raster_array # noqa
> 7 import rioxarray.raster_dataset # noqa
> ----> 8 from rioxarray._io import open_rasterio # noqa
> 9 from rioxarray._options import set_options # noqa
> 10 from rioxarray._show_versions import show_versions # noqa
>
> ~\anaconda3\envs\Raster Analysis\lib\site-packages\rioxarray\_io.py in
> <module>
> 33 # TODO: should this be GDAL_LOCK instead?
> 34 RASTERIO_LOCK = SerializableLock()
> ---> 35 NO_LOCK = contextlib.nullcontext()
> 36
> 37
>
> AttributeError: module 'contextlib' has no attribute 'nullcontext'
作为测试,我尝试在JupyterNotebook的新行上导入rioxarray,但产生了相同的错误
目前没有回答
相关问题 更多 >
编程相关推荐