python用cartopy包画地图_python – 使用Cartopy在地图上显示图像时的投影问题
我有一些我想用Cartopy顯示的衛(wèi)星圖像數(shù)據(jù).我已成功按照?qǐng)D像示例詳細(xì)介紹了here.導(dǎo)致此代碼:
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
fig = plt.figure(figsize=(12,12))
img_extent = (-77,-59,9,26)
ax = plt.axes(projection=ccrs.PlateCarree())
# image data coming from server,code not shown
ax.imshow(img,origin='upper',extent=img_extent)
ax.set_xmargin(0.05)
ax.set_ymargin(0.10)
# mark a known place to help us geo-locate ourselves
ax.plot(-117.1625,32.715,'bo',markersize=7)
ax.text(-117,33,'San Diego')
ax.coastlines()
ax.gridlines()
plt.show()
此代碼生成以下圖像
我的問題是衛(wèi)星圖像數(shù)據(jù)不在PlateCarree投影中,而是墨卡托投影.
但是當(dāng)我得到軸對(duì)象時(shí)
ax = plt.axes(projection=ccrs.Mercator())
我失去了海岸線.
我看到了here報(bào)告的問題.但是
ax.set_global()
得到這張圖片的結(jié)果:
數(shù)據(jù)不存在,圣地亞哥位置錯(cuò)誤.緯度/經(jīng)度范圍也發(fā)生了變化.我究竟做錯(cuò)了什么?
發(fā)布討論更新
主要問題是我沒有使用transform_points方法在目標(biāo)投影中正確指定圖像范圍.我還必須具體說明菲爾建議的imshow方法中的坐標(biāo)參考系統(tǒng).這是正確的代碼:
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
proj = ccrs.Mercator()
fig = plt.figure(figsize=(12,12))
extents = proj.transform_points(ccrs.Geodetic(),np.array([-77,-59]),np.array([9,26]))
img_extents = (extents[0][0],extents[1][0],extents[0][6],extents[1][7] )
ax = plt.axes(projection=proj)
# image data coming from server,extent=img_extents,transform=proj)
ax.set_xmargin(0.05)
ax.set_ymargin(0.10)
# mark a known place to help us geo-locate ourselves
ax.plot(-117.1625,markersize=7,transform=ccrs.Geodetic())
ax.text(-117,'San Diego',transform=ccrs.Geodetic())
ax.coastlines()
ax.gridlines()
plt.show()
導(dǎo)致這個(gè)正確地理投影的衛(wèi)星圖像:
總結(jié)
以上是生活随笔為你收集整理的python用cartopy包画地图_python – 使用Cartopy在地图上显示图像时的投影问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html项目符号正方形,html – 列
- 下一篇: A*算法求解迷宫问题(算法讲解与证明、p