如何将底图添加到已使用 geopanda 和上下文进行屏蔽的 geotiff

问题描述

我是 geopandas 和 Rasterio 的新手。 我设法用我的蒙版 geotiff 数据绘制了一个图,并使用变换来获得轴上正确的坐标值。 我现在想使用上下文添加底图,但我很挣扎。

这是我目前的代码...

import geopandas
import matplotlib.pyplot as plt
import Rasterio
import Rasterio.plot
from Rasterio import mask
import numpy as np
import contextily as ctx

shapes = [
    { "type": "polygon","coordinates": [ [ [ -4.034278075119148,50.408709729045114 ],[ -4.017163720775412,50.412558554591797 ],[ -4.004531592262922,50.405432114946152 ],[ -4.014160721995826,50.397385783476295 ],[ -4.02723873431488,50.395358910428506 ],[ -4.03522008284683,50.40227262174929 ],[ -4.034278075119148,50.408709729045114 ] ] ] } 
]


with Rasterio.open("/home/xxx/Desktop/xxx/dataprocess/data/sx-landcover-84.tif") as src:
    lc_out_image,lc_out_transform = Rasterio.mask.mask(src,shapes,crop=True)
    out_Meta = src.Meta
    out_Meta.update({"driver": "GTiff","height": lc_out_image.shape[0],"width": lc_out_image.shape[1],"transform": lc_out_transform})
    lc_out_image[lc_out_image <= 0] = np.nan
    fig,ax = plt.subplots()
    Rasterio.plot.show(lc_out_image,ax=ax,transform=lc_out_transform)

我认为 contexily 可以做到这一点,但我在两个库之间迷失了方向。 你能帮忙吗?

解决方法

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

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

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