在matplotlibbasemap中有没有从GPS点绘制航向(360)的功能?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在matplotlibbasemap中有没有从GPS点绘制航向(360)的功能?相关的知识,希望对你有一定的参考价值。

我需要绘制一艘船在海洋中的水下图。我有GPS数据和航向数据。数据集在pandas数据框中。我想把车辆的航向绘制成一个从GPS主线出来的箭头。

enter image description here

这张图是我的GPS航向。我想在basemap中做这件事,但我似乎甚至不知道如何做到这一点是matplotlib。下面我有一个例子,我的代码。

import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
from matplotlib import style
import numpy as np
import math
from mpl_toolkits.basemap import Basemap



data = pd.read_csv('dataset')
style.use('seaborn')

data['pd_datetime'] = pd.to_datetime(data['time (UTC)'])
       # convert current date format into pandas date time format 

gpsdata = data.loc[:, ['m_gps_lon (DDMM.MMMM)', 'm_gps_lat (DDMM.MMMM)']] #from my data set
gpsdata = gpsdata.dropna() 
plt.plot(gpsdata['m_gps_lon (DDMM.MMMM)'], gpsdata['m_gps_lat (DDMM.MMMM)'], '-.')
plt.title('GPS')
plt.xlabel('lon')
plt.ylabel('lat')
plt.show()

place = 'some area'
c = {'llclon': -55, 'llclat': 55, 'urclon': 55, 'urclat': 55}
map = Basemap(
    llcrnrlon= c['llclon'], llcrnrlat= c['llclat'],
    urcrnrlon= c['urclon'], urcrnrlat= c['urclat'], 
    resolution='l')
    #projections: cyl=cylindrical equidistant projection, ortho=orthographic
map.drawcoastlines()

plt.plot(gpsdata['m_gps_lon (DDMM.MMMM)'], gpsdata['m_gps_lat (DDMM.MMMM)'], '-.')
plt.plot(data['pd_datetime'], np.rad2deg(data['m_heading (rad)']), '.', color='red') #i thought this would at least plot a point. but it doesnt do anything. all headings are in compass headings. not nessisarily pointing in the direction of the track
plt.show()
plt.show()

任何帮助将是非常感激

答案

所以,这似乎是工作。我使用一个数学函数来发布一个新的位置,使用标题和一个任意的距离,只是为了可视化的标题。

import numpy as np
import pandas as pd

dec = np.deg2rad(22.74)         #NOAA declination correction for area 
R = 6378.1                      #Radius of the Earth
brng = np.deg2rad(320) - dec    #bearing needs to be in rad 
d = 1                           #Distance in km, this didn't matter to me. 1 km is arbitrary, but it could matter to you. 

### c_heading
heading_lat1 = np.deg2rad(pandas_df['dataframe header latitude (DD.DDDD)'])
heading_lon1 = np.deg2rad(pandas_df['dataframe header longitude (DD.DDDD)'])

heading_lat2 = np.arcsin(np.sin(heading_lat1)*np.cos(d/R) + np.cos(heading_lat1)*np.sin(d/R)*np.cos(brng)) 
heading_lon2 = heading_lon1 + np.arctan2(np.sin(brng)*np.sin(d/R)*np.cos(heading_lat1), 
        np.cos(d/R) - np.sin(heading_lat1)*np.sin(heading_lat2))

heading_lat2 = np.rad2deg(heading_lat2)
heading_lon2 = np.rad2deg(heading_lon2)

请注意,我使用的是一个 pandas dataframe,这将与 import math 和数学函数。但从我目前的经验来看,数学并不能很好地与pandas的dataframe玩耍

希望能帮助到大家

以上是关于在matplotlibbasemap中有没有从GPS点绘制航向(360)的功能?的主要内容,如果未能解决你的问题,请参考以下文章

3GP有没有能转换音频和视频的

如何使用.mp4,webm,3gp格式从视频生成缩略图

text 从GP中删除FontAwesome

php Gravity Perks // GP电子商务领域//从订单摘要中扣除存款

从 Skopt 中的检查点恢复 gp_minimize 进程

如何在android中处理音频(.3gp)文件[关闭]