我想将lon / lat(以度为单位)转换为x / y地图投影坐标(以米为单位),但要使用cartopy + pyplot而不是底图。
说这是底图代码:
api
我想在cartopy中模拟类似的功能,该怎么做?
答案 0 :(得分:1)
据我所知,实现适合用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()
输出图将是: