我有一张 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/