Python将 map 绘制到球体上

标签 python plot 3d visualization cartopy

我有一张 map ,我想投影到一个球体上,我按照另一个线程中的建议使用了 cartopy。我在 Jupyter 中编程。

我的代码是:

import os
import cartopy.crs as ccrs
import matplotlib.pyplot as plt

os.chdir(os.getenv("HOME"))
os.chdir("Downloads/")
img = plt.imread("europamap1.jpg")

plt.figure(figsize=(3, 3))

ax = plt.axes(projection=ccrs.Orthographic(-10, 45))
ax.gridlines(color="black", linestyle="dotted")
ax.imshow(img, origin="upper", extent=(-180, 180, -90, 90),
          transform=ccrs.PlateCarree())  # Important

plt.show()

我得到的是一个白色实心圆圈 enter image description here

我不知道为什么我看不到任何网格线和图像!我尝试 plot.show(img) 并加载图像!我基本上只是从 this thread 复制并粘贴

最佳答案

您使用 plt.imread 加载的图像文件不是地理空间栅格格式,它通常是以 .tiff 扩展名结尾的 GeoTIFF 文件。

问题是您的图像缺少与 cartopy 对齐的坐标引用系统 (CRS)。例如 print(img.crs) 很可能不会打印 CRS。

要投影您的数据,您需要找到一个 GeoTIFF 文件并将 CRS 与 cartopy 使用的投影对齐 - 例如 ccrs.PlateCarree()

可以在此处找到一些测试卫星图像:https://gisgeography.com/usgs-earth-explorer-download-free-landsat-imagery/ .

读取和写入栅格数据,参见rasterio:https://rasterio.readthedocs.io/en/latest/ .

这是一个使用 GeoTIFF 的示例,来自评论中链接的源。 https://photojournal.jpl.nasa.gov/tiff/PIA03526.tif :.

import matplotlib.pyplot as plt
import rasterio
from rasterio import plot

src = rasterio.open(r"../tests/data/PIA03526.tif")
plot.show(src)

关于Python将 map 绘制到球体上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53073364/

相关文章:

python - 读取两行的值并用python写入一行

javascript - 在 javascript/d3 中具有力导向布局的 Beeswarm 图

matlab - 如何在 MATLAB 图形窗口的边缘周围创建边框?

javascript - 当相机移动三个js时线消失

python - 使用 Python 查找包含一组关键字之一的句子

python - 在没有输入的情况下使用 GNU 并行生成 n 个工作线程

特定范围内向量的 MATLAB 绘图

javascript - 如何在Javascript中正确声明和调用3维 map ?

python - 使用 np.outer 生成圆柱面

python - 属性错误 : module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel' for PyQt5 5. 15.0