-
Notifications
You must be signed in to change notification settings - Fork 2
/
GeoLife_trajectory_reading.m
71 lines (53 loc) · 2.21 KB
/
GeoLife_trajectory_reading.m
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
function [latLong,numberOfEffectiveRecord,visitingTime] = GeoLife_trajectory_reading(param)
maindir = param.inputFile;
if length(dir(maindir)) == 0
error('Error, Please check your file path!');
end
maxline = param.readingNumOfTraj;
[latLong,numberOfEffectiveRecord,~,visitingTime] = Dfs_dictory(maindir,0,maxline);
end
function [latLong,numberOfTrajectory,flag,visitingTime] = Dfs_dictory(maindir,tline,maxline)
latLong = [];
visitingTime = {};
numberOfTrajectory = 0;
subdir = dir(maindir);
flag = false;
for i = 1 : length(subdir)
if isequal(subdir( i ).name,'.')|| isequal(subdir(i).name,'..') % if file is a directory then pass
continue;
end
fileName = fullfile(maindir, subdir(i).name);
fprintf('Load path/file = %s\n',fileName);
if subdir(i).isdir
[latLong1,numberOfTrajectory1,flag] = Dfs_dictory(fileName,max(tline,numberOfTrajectory),maxline);
latLong = [latLong;latLong1];
numberOfTrajectory = numberOfTrajectory + numberOfTrajectory1;
if flag
return;
end
continue;
end
%% for a single file
if ~isequal(fileName(end-3:end), '.plt')
if ~isequal(fileName(end-3:end), '.txt')
continue;
end
end
fileID = fopen(fileName);
textscan(fileID,'%s',6,'Delimiter','\n');
% C = textscan(fileID,'%f %f %*s %*s %*f %{yyyy-MM-dd}D %{hh:mm:ss}D','Delimiter',',');
C = textscan(fileID,'%f %f %*s %*s %*f %[^\n]','Delimiter',',');
fclose(fileID);
% latLong = [latLong;str2num(subdir(i).name(1:end-4)) * ones(length(C{1}),1),C{1},C{2}];
latLong = [latLong;tline * ones(length(C{1}),1),C{1},C{2}];
strtime = C{3};
time = cellfun(@(x) textscan(x,'%{yyyy-MM-dd,HH:mm:ss}D','Delimiter',';'),strtime);
visitingTime = [visitingTime; time];
numberOfTrajectory = numberOfTrajectory + 1;
if(tline >= maxline-1)
flag = true;
return;
end
tline = tline + 1;
end
end