Cartopy Splitting Large Circle

问题描述 投票:0回答:1

我正在尝试绘制科罗拉多州丹佛市天空的可见区域,并将该区域显示为地图投影上的阴影“圆圈”。

我期待地图上出现一个以丹佛为中心的扭曲圆圈(由于地图投影)。当我尝试绘制带填充的匀称圆时,它似乎正确居中,但它沿纬度分开,如图所示。我无法弄清楚为什么会这样做以及如何纠正它。期望的结果是曲线上方的区域(所有北美和俄罗斯上方的海洋)都被涂成红色。

import numpy as np
import cartopy.geodesic as cgeod
import cartopy.crs as crs
import cartopy.feature as cfeature
import shapely
import matplotlib.pyplot as plt

# SET CONSTANTS
RE = 6371008.8 # meters, WGS84 Sphere
h = 35786000.0 # meters, GEO

def arc_dist_to_FOV(h, ah):
    a = (np.pi/180)*(90 + ah) # radians
    b = np.arcsin(RE * np.sin(a)/(RE + h)) # radians
    g = np.pi - a - b # radians
    d = (180/np.pi)*g*RE
    return d

cm = 0
proj = crs.PlateCarree(central_longitude=cm)
fig = plt.figure(figsize=(10,8))
ax = fig.add_subplot(1,1,1, projection=proj)

ax.set_global()

ax.add_feature(cfeature.COASTLINE, edgecolor='black')
ax.add_feature(cfeature.BORDERS, edgecolor='black')
ax.add_feature(cfeature.STATES, edgecolor='black')

ax.stock_img()
# ax.background_img(name='BM', resolution='high')
ax.gridlines(draw_labels=True, crs=proj)
lat, lon = 39.7392, -104.985

plt.scatter(x=lon, y=lat, color='blue', s=10, transform=proj)

# COMPUTE FOV
ah = 20 # degrees above horizon
dFOV = arc_dist_to_FOV(h, ah)
site_lat = lat
site_lon = lon
    
# ADD SHAPES TO MAP
circle_points = cgeod.Geodesic().circle(lon=site_lon, lat=site_lat, radius=dFOV, n_samples=1000, endpoint=False)
geom = shapely.geometry.Polygon(circle_points)
ax.add_geometries((geom,), crs=proj, alpha=0.5, facecolor='red', edgecolor='black', linewidth=1)

# must save BEFORE show cmd
# plt.savefig('name.png', bbox_inches='tight', dpi=300)

plt.show()```
python matplotlib cartopy shapley
1个回答
0
投票

对于在任何投影上绘制的(投影)圆,可以使用方法

.tissot()
。这大大简化了在地图上绘制圆圈的过程。

下图中大圆圈的(投影)使用了这行代码:

ax.tissot(rad_km=dFOV/1000, lons=[site_lon,], lats=[site_lat,], n_samples=128, fc="red", ec="black", alpha=0.75)

用正射投影来看,剧情大概是这样的:

© www.soinside.com 2019 - 2024. All rights reserved.