python画地球仪_如何选择纬度和经度在地球仪上形成一个“矩形”?

我有一个在经纬度网格上的数据集。我需要从这个数据集中选择一个近乎完美的“矩形”覆盖北美。某物,但位于北美上空:

1。我如何选择纬度和经度?

因为经度向两极靠拢,所以我需要更多的经度往北。在

这是我的拙劣和可能不正确的尝试。我猜这是cartopy中的一行代码,但我不知道我在寻找什么样的转换。在

我的矩形高度从0°到75°N纬度。我在计算每个纬度的经度跨度,这样水平宽度(米)等于0度经度215°到305°的距离。(矩形水平居中约260°。)import numpy as np

import cartopy.crs as ccrs

import matplotlib.pyplot as plt

def long_meters_at_lat(lat):

"""Calculate distance (in meters) between longitudes at a given latitude."""

a = 6378137.0

b = 6356752.3142

e_sqr = a**2 / b**2 -1

lat = lat * 2 * np.pi / 360

return np.pi * a * np.cos(lat) / (180 * np.power(1 - e_sqr * np.square(np.sin(lat)), .5))

min_lat, max_lat = 0, 75

min_lon, max_lon = 215, 305 # Desired longitude spread at at min_lat

central_lon = (max_lon + min_lon) // 2

dist_betn_lats = 111000 # In meters. Roughly constant

lat_range, lon_range = np.arange(max_lat, min_lat-1, -1), np.arange(min_lon, max_lon+1)

x_idxs, y_idxs = np.meshgrid(lon_range, lat_range)

y_meters = (y_idxs - min_lat) * dist_betn_lats

y_lats = y_idxs + min_lat

dist_betn_lons_at_min_lat = long_meters_at_lat(lat_range[-1])

x_meters = (x_idxs - central_lon) * dist_betn_lons_at_min_lat # Plus/minus around central longitude

x_lons = central_lon + np.round(x_meters/long_meters_at_lat(lat_range)[:, None]).astype('uint16')

assert ((x_lons[:, -1] - x_lons[:, 0]) <= 360).all(), 'The area is wrapping around on itself'

x_lons = np.where(x_lons >= 360, x_lons-360, x_lons)

这就是y_lats, x_lons的样子,看起来很正常(右上角的低经度绕了360°)。在

^{pr2}$

2。我如何在地球仪上绘制这些纬度/经度的数据?

我试过下面明显的,但只在右边切了一小段。在crs = ccrs.PlateCarree()

u = np.random.rand(*x_lons.shape)

v = np.random.rand(*x_lons.shape)

ax = plt.axes(projection=ccrs.Orthographic())

ax.add_feature(cartopy.feature.OCEAN, zorder=0)

ax.add_feature(cartopy.feature.LAND, zorder=0, edgecolor='black')

ax.set_global()

ax.scatter(y_lats, x_lons, u, v, transform=crs)

plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值