Blame view

gpx2mat.m 1.48 KB
45d5c458   Dany Dumont   Premier depot de ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function gpx2mat(gpxfile)
% GPX2MAT - Convert gpx files to mat files
%
% Syntax:  gpx2mat(gpxfile)
% 
% Inputs:
%    gpxfile - The name of the gpx file to convert, excluding the .gpx
%              extension
% 
% Example:
%    g_interp('spot_device')
% 
% Other m-files required: gpxread
% Subfunctions: none
% 
% See also: GPXREAD, TR_MAP, TR_MERGE

% Author: Dany Dumont
% UQAR/ISMER
% email: dany_dumont@uqar.ca
% Website: http://www.ismer.ca/dumont-dany
% September 2014
% ______________________________________________________________________
% 

curdir = pwd;
matdir = [curdir,'/mat'];

file = dir(['./',gpxfile,'.gpx']);

wpt = gpxread(file.name);

lat   = wpt.Latitude;
lon   = wpt.Longitude;
clock = wpt.Time;

trk = gpxread(file.name,'FeatureType','track','Index',1);

ind = 0;
while ~isempty(trk)
    ind = ind + 1;
    trk = gpxread(file.name,'FeatureType','track','Index',ind);
    if ~isempty(trk)
        lat   = [lat   trk.Latitude];
        lon   = [lon   trk.Longitude];
        clock = [clock trk.Time];
    end
end

N = length(lat);

for n = 1:N

    yr(n) = str2double(clock{n}(1:4));
    mo(n) = str2double(clock{n}(6:7));
    da(n) = str2double(clock{n}(9:10));
    hh(n) = str2double(clock{n}(12:13));
    mm(n) = str2double(clock{n}(15:16));
    ss(n) = str2double(clock{n}(18:19));

    time(n) = datenum([yr(n) mo(n) da(n) hh(n) mm(n) ss(n)]);
end

data = [time' lon' lat'];

data = sortrows(data,1);

if ~exist(matdir,'dir')
    mkdir(matdir)
end

save([matdir,'/',gpxfile],'data');