【发布时间】:2022-01-18 21:15:50
【问题描述】:
我想将起点 (lat_1 lon_1) 的飞机连接到终点 (lat_2 lon_2)。我使用these 数据。
| callsign | latitude_1 | longitude_1 | latitude_2 | longitude_2 | |
|---|---|---|---|---|---|
| 0 | HBAL102 | -4.82114 | -76.3194 | -4.5249 | -79.0103 |
| 1 | AUA1028 | -33.9635 | 151.181 | 48.1174 | 16.55 |
| 2 | ABW120 | 41.9659 | -87.8832 | 55.9835 | 37.4958 |
| 3 | CSN461 | 33.9363 | -118.414 | 50.0357 | 8.5723 |
| 4 | ETH3730 | 25.3864 | 55.4221 | 50.6342 | 5.43903 |
但不幸的是,当我用 shapely 创建 LineString 时,我会得到一个不正确的结果。我使用了旋转和仿射等所有方法,但它不正确。
代码:
cols = pd.read_csv("/content/dirct_lines.csv",sep=";")
line = cols[["callsign","latitude_1","longitude_1","latitude_2","longitude_2"]].dropna()
line['geometry'] = line.apply(lambda x: [(x['latitude_1'],
x['longitude_1']),
(x['latitude_2'],
x['longitude_2'])], axis = 1)
geoline = gpd.GeoDataFrame(line,geometry="geometry",
crs="EPSG:4326")
import matplotlib.pyplot as plt
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
ax = world.plot(figsize=(14,9),
color='white', edgecolor='black')
geoline.plot(figsize=(14,9),ax=ax,facecolor = 'lightgrey', linewidth = 1.75,
edgecolor = 'red',
alpha = 2)
plt.show()
让我感兴趣的是,当我使用 Matplotlib 创建线条时,一切都是正确的。
代码:
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(12, 8))
ax = fig.add_subplot(projection=ccrs.PlateCarree())
ax.stock_img()
org_lon, org_lat = cols["longitude_1"], cols["latitude_1"]
dst_lon, dst_lat = cols["longitude_2"], cols["latitude_2"]
plt.plot([org_lon, dst_lon], [org_lat, dst_lat],
color='black', linewidth=0.5, marker='_',
transform=ccrs.PlateCarree()
)
plt.savefig(f"fight_path.png",dpi=60,facecolor = None, bbox_inches = 'tight', pad_inches = None)
plt.show()
有什么问题?
为什么形状不正确?
【问题讨论】:
-
检查纬度/经度顺序,许多图书馆更喜欢经度/纬度顺序,参见例如gis.stackexchange.com/questions/376751/…
-
谢天谢地,是的,当我更改它们时,一切正常,
标签: matplotlib gis geospatial geopandas shapely