有些时候需要展示一下行车轨迹,但是直接画图结果并不直观,而且也没有环境支撑,效果并不好。而google earth提供一种公开标准的kml/kmz文件,可以通过将行车轨迹坐标转成该文件格式,从而实现基于google earth的行车轨迹展示。
rtklib已经存在pos2kml的函数及其功能,但是考虑到在matlab调用并不方便,还需要使用文本作为转换媒介,而kml文件结构也并不复杂,故此处重写了matlab版本的pos2mal,能基本实现位置展示及使用不同的颜色代表不同的属性。
使用方法如下:
pos2kml(lat,lon,hgt,att,out_file)
% brief Generate google earth kml file
% Input: lat (nx1,double) : latitude vector
% lon (nx1,double) : longitude vector
% hgt (nx1,double or []) : height vector
% att (nx1,integer or []) : attributes vector, stand for
% different color points, only 7 color supported.
% out_file (string) : out kml file path and name
% Call Example:
% 1. pos2kml(lat,lon,[],[],'out.kml');
% 2. pos2kml(lat,lon,[],ones(length(lat),1),'out.kml');
该函数会直接生 out.kml
文件(建议添加 .kml
尾辍,方便google earth识别),然后使用google earth打开该文件即可。
代码已托管至github, 下载地址如下: