如何从地理底图中转换为地图投影?

How to convert to map projection from geographic like in basemap?

我想将 lon/lat(以度为单位)转换为 x/y 地图投影坐标(以米为单位),但使用的是 cartopy + pyplot 而不是底图。

假设这是底图代码:

>>> from mpl_toolkits.basemap import Basemap
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> # read in topo data (on a regular lat/lon grid)
>>> etopo = np.loadtxt('etopo20data.gz')
>>> lons  = np.loadtxt('etopo20lons.gz')
>>> lats  = np.loadtxt('etopo20lats.gz')
>>> # create Basemap instance for Robinson projection.
>>> m = Basemap(projection='robin',lon_0=0.5*(lons[0]+lons[-1]))
>>> # compute map projection coordinates for lat/lon grid.
>>> x, y = m(*np.meshgrid(lons,lats))

我想在 cartopy 中模拟类似的功能,我该怎么做?

据我所知,使用 Cartopy 实现适合绘图的网格点的步骤是不同的,而且更加困难。

这是使用 Cartopy 的工作代码:

import matplotlib.pyplot as plt
import cartopy
import cartopy.crs as ccrs
import numpy as np

# create arrays of values for long and lat
lons = np.linspace(0,160,10)
lats = np.linspace(0,70,5)

# create meshgrid of points
x, y = np.meshgrid(lons, lats)

# select a CRS/projection to tranform/plot points for demo
use_proj = ccrs.Robinson();

# transform all the meshgrid points arrays ..
# .. from geodetic long/lat to Robinson x/y/z
out_xyz = use_proj.transform_points(ccrs.Geodetic(), x, y)
# out_xyz.shape -> (5, 10, 3)

# separate x_array, y_array from the result(x,y,z) above
x_array = out_xyz[:,:,0]
y_array = out_xyz[:,:,1]

# setup fig/axis and plot the meshgrid of points
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1], projection=use_proj)
ax.add_feature(cartopy.feature.LAND, facecolor='lightgray')
ax.scatter(x_array, y_array, s=25, c="r", zorder=10)
ax.set_global()
plt.show()

输出图将是: