如何将屏幕坐标转换为Cartopy中的地理坐标(去重)?
我想知道如何把屏幕上左上角(TL)和右下角(BR)的坐标,转换成拉姆伯特投影的坐标。这个转换是基于两个拉姆伯特投影坐标点(BL和TR)来进行的。我觉得这个过程叫“解错位”,但在Cartopy里找不到相关的例子。
这里有生成这些点的代码:
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
ll_lon, ll_lat = -10,40
ur_lon, ur_lat = 10,60
c_lon, c_lat = (ll_lon+ur_lon)/2, (ll_lat+ur_lat)/2
plt.figure(figsize=[12,12])
proj = ccrs.LambertConformal(central_longitude=c_lon, central_latitude=c_lat)
ax = plt.axes(projection=proj)
ax.set_extent([-25,+25,35,65], ccrs.PlateCarree())
ax.scatter(ll_lon,ll_lat, transform=ccrs.PlateCarree())
# ax.scatter(ur_lon,ll_lat, transform=ccrs.PlateCarree()) # incorrect
# ax.scatter(ll_lon,ur_lat, transform=ccrs.PlateCarree()) # incorrect
ax.scatter(ur_lon,ur_lat, transform=ccrs.PlateCarree())
ax.scatter(c_lon,c_lat, transform=ccrs.PlateCarree())
ax.add_feature(cfeature.OCEAN,facecolor='paleturquoise',alpha=0.4)
ax.add_feature(cfeature.BORDERS,edgecolor='black')
ax.add_feature(cfeature.COASTLINE,edgecolor='black')
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, x_inline=False, y_inline=False, linewidth=0.33, color='k',alpha=0.5)
gl.right_labels = gl.top_labels = False
plt.show()
提前谢谢你的帮助!:)
2 个回答
1
从地理坐标 (λ1, φ1)
(西南角)和 (λ2, φ2)
(东北角)获取投影坐标 (x1, y1)
和 (x2, y2)
,那么东南角就是 (x2, y1)
,而西北角就是 (x1, y2)
。
3
我觉得你想要的是 transform_point
这个方法:
plot_proj = ccrs.LambertConformal(central_longitude=c_lon, central_latitude=c_lat)
source_proj = ccrs.PlateCarree()
# Get lower left and upper right points in Lambert Conformal system.
l_lcx, l_lcy = plot_proj.transform_point(ll_lon, ll_lat, source_proj)
r_lcx, u_lcy = plot_proj.transform_point(ur_lon, ur_lat, source_proj)
# Convert Lambert Conformal's upper left and lower right back to lat and lon.
ul_lon, ul_lat = source_proj.transform_point(l_lcx, u_lcy, plot_proj)
lr_lon, lr_lat = source_proj.transform_point(r_lcx, l_lcy, plot_proj)