How would I calculate the coordinates of the top-left (TL) and bottom-right (BR) points as seen on a screen to coordinates in a Lambert Projection, given two points (BL and TR) in Lambert Projection coordinates using Cartopy? I think the term for this is "unstaggering" but I cannot find any examples in Cartopy.
The code to reproduce these points is given here:
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()
Thanks in advance for any help! :)
I think you want the transform_point
method:
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)