-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSummary.tex
More file actions
312 lines (265 loc) · 12.5 KB
/
Summary.tex
File metadata and controls
312 lines (265 loc) · 12.5 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[utf8]{inputenc}
\else % if luatex or xelatex
\ifxetex
\usepackage{mathspec}
\usepackage{xltxtra,xunicode}
\else
\usepackage{fontspec}
\fi
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\newcommand{\euro}{€}
\fi
% use microtype if available
\IfFileExists{microtype.sty}{\usepackage{microtype}}{}
\usepackage[margin=1in]{geometry}
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{{#1}}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{{#1}}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{{#1}}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{{#1}}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{{#1}}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{{#1}}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{{#1}}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{{#1}}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{{#1}}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{{#1}}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{{#1}}}
\newcommand{\RegionMarkerTok}[1]{{#1}}
\newcommand{\ErrorTok}[1]{\textbf{{#1}}}
\newcommand{\NormalTok}[1]{{#1}}
\usepackage{graphicx}
% Redefine \includegraphics so that, unless explicit options are
% given, the image width will not exceed the width of the page.
% Images get their normal width if they fit onto the page, but
% are scaled down if they would overflow the margins.
\makeatletter
\def\ScaleIfNeeded{%
\ifdim\Gin@nat@width>\linewidth
\linewidth
\else
\Gin@nat@width
\fi
}
\makeatother
\let\Oldincludegraphics\includegraphics
{%
\catcode`\@=11\relax%
\gdef\includegraphics{\@ifnextchar[{\Oldincludegraphics}{\Oldincludegraphics[width=\ScaleIfNeeded]}}%
}%
\ifxetex
\usepackage[setpagesize=false, % page size defined by xetex
unicode=false, % unicode breaks when used with xetex
xetex]{hyperref}
\else
\usepackage[unicode=true]{hyperref}
\fi
\hypersetup{breaklinks=true,
bookmarks=true,
pdfauthor={Nikolai Gorte \& Simon Schoemaker},
pdftitle={Using enviroCar data in R},
colorlinks=true,
citecolor=blue,
urlcolor=blue,
linkcolor=magenta,
pdfborder={0 0 0}}
\urlstyle{same} % don't use monospace font for urls
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\setcounter{secnumdepth}{0}
%%% Change title format to be more compact
\usepackage{titling}
\setlength{\droptitle}{-2em}
\title{Using enviroCar data in R}
\pretitle{\vspace{\droptitle}\centering\huge}
\posttitle{\par}
\author{Nikolai Gorte \& Simon Schoemaker}
\preauthor{\centering\large\emph}
\postauthor{\par}
\predate{\centering\large\emph}
\postdate{\par}
\date{November 20, 2014}
\begin{document}
\maketitle
\section{enviroCaR - Analysis of Car
Trajectories}\label{envirocar---analysis-of-car-trajectories}
The capital R in the name ``enviroCaR'' obviously reveals that it is the
R package corresponding to the project we will work on
(\url{https://envirocar.org/}). In general, \texttt{enviroCaR} provides
basic functions to load and analyse measurements from the enviroCar
server (Pebesma, Stasch, and Wirwahn 2014).
R is a open-source software for general data analysis. It compiles and
runs on a wide variety of platforms and provides a big sample of
statistical and graphical methods. Furthermore, R is easily extendable
through a massive amount of so-called packages. Currently, there are
round about 6000 packages available on the ``Comprehensive R Archive
Network'', short called CRAN. The number of developers and published
packages are growing continuously. Additionally, each package has got
help pages, several documentations and useful example code chunks (R
Core Team 2014).
As mentioned before R packages are usually available on CRAN and can be
installed from there relatively straightforward. However, the enviroCaR
package is not on CRAN as yet and needs to be installed from GitHub
(\url{https://github.com/enviroCar/enviroCaR}). For the installation you
can use the \texttt{devtools} package to accomplish this easily (Wickham
and Chang 2014).
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{library}\NormalTok{(devtools)}
\KeywordTok{install_github}\NormalTok{(}\StringTok{'enviroCaR'}\NormalTok{, }\StringTok{'enviroCar'}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\section{Trajectories}\label{trajectories}
For improving the overall handling of trajectories in R a package called
\texttt{trajectories} was developed by Edzer Pebesma and Benedikt Klus.
This package provides useful methods and classes to work with trajectory
data (Pebesma and Klus 2014).
In general, there are three data classes for the representation of
trajectories.
The first one is the \texttt{Track}, which represents one single track.
The class contains five slots \texttt{@sp} to store the geometry like
coordinates, \texttt{@time} to store the time, \texttt{@endtime} to
store the end time when having generalized line geometries with one
value per attribute for a set of points, \texttt{@data} to store the
attributes and \texttt{@connections} to keep a record of attribute data
between points like speed and distance.
Furthermore, the class \texttt{Tracks} embodies a collection of tracks
followed by a single person, animal or object. The class contains two
slots: one for storing the tracks as objects of class \texttt{Track} and
one for holding a summary record for each track.
The last one is the class \texttt{TracksCollection}, which is also a
collection of tracks but now in contrast to \texttt{Tracks} followed by
many persons, animals or objects. Equal to \texttt{Tracks} the class has
the same two slots.
\section{Import enviroCar data}\label{import-envirocar-data}
To load data from the enviroCar server you can easily use two provided
import functions from the \texttt{enviroCaR} package. Therefore,
\texttt{importSingleTrack} allows you to import one single track and
stores the loaded track as an object of class \texttt{Tracks} with a
list of one \texttt{Track}. Required arguments for the function are the
\texttt{serverUrl} and the \texttt{trackID}.
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{require}\NormalTok{(enviroCaR)}
\NormalTok{tracks <-}\StringTok{ }\KeywordTok{importSingleTrack}\NormalTok{(}\StringTok{"https://envirocar.org/api/stable"}\NormalTok{, }\StringTok{"52af4fd3e4b0593cce13bfc7"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
For importing several tracks you can use the function
\texttt{importEnviroCar}. For this, you can select the tracks either
with their Ids or a defined bounding box or a certain time interval. In
the following example we use the track Ids to specify the data that
should be retrieved.
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{require}\NormalTok{(sp)}
\NormalTok{ids <-}\StringTok{ }\KeywordTok{getTrackIDs}\NormalTok{(}\StringTok{"https://envirocar.org/api/stable"}\NormalTok{, }\KeywordTok{bbox}\NormalTok{(tracks))}
\NormalTok{trcol <-}\StringTok{ }\KeywordTok{importEnviroCar}\NormalTok{(}\StringTok{"https://envirocar.org/api/stable"}\NormalTok{, ids[}\DecValTok{4}\NormalTok{:}\DecValTok{6}\NormalTok{])}
\end{Highlighting}
\end{Shaded}
\texttt{trcol} is an object of the class \texttt{TracksCollection}.
\section{Plot}\label{plot}
To plot the \texttt{TracksCollection} you can use the \texttt{stplot}
from the \texttt{spacetime} package (Pebesma 2012). For the plot you can
also specify an certain attribute (see the example below). currently,
the plot method only works for objects of the class
\texttt{TracksCollection}.
\begin{Shaded}
\begin{Highlighting}[]
\KeywordTok{require}\NormalTok{(spacetime)}
\KeywordTok{stplot}\NormalTok{(trcol, }\DataTypeTok{attr =} \StringTok{"speed"}\NormalTok{, }\DataTypeTok{lwd =} \DecValTok{3}\NormalTok{, }\DataTypeTok{by =} \StringTok{"IDs"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{figure}[h!]
\centering
\includegraphics[width=0.8\textwidth]{figures/stplot.png}
\caption{Plot TracksCollection with attribute speed}
\label{fig:st}
\end{figure}
\section{Aggregation}\label{aggregation}
One function provided by the enviroCaR package is
\texttt{aggregateTrack}. This function is used to aggregate measurements
of a Track object.\\It is possible to specify the phenomenon for
aggregation, the interval size of measurements that have to be
aggregated and a function for aggregation (e.g.~mean).\\Aggregation over
time is not possible at the moment! In Figure 2 we can see an example of
an aggregated track. The raw track (black) is aggregated to six points
(red).
\begin{figure}[htbp]
\centering
\includegraphics{figures/agg.png}
\caption{Aggregated Track}
\end{figure}
\section{Map Matching}\label{map-matching}
Map matching is the process of matching GPS trajectories to a digital
road network and is done using map matching algorithms. This is
necessary because positions acquired from GPS, as they are in the
enviroCaR project, are affected by several kind of errors resulting in
inaccurate positions on maps.\\Matching the enviroCar trajectories to a
digital road network would not only improve the visual representation,
but could also be useful when it comes to analysis or comparison of
trajectories.
One possible way of achieving this is the \texttt{fuzzyMM} package
(Gorte 2014) which implements a fuzzy logic based map matching
algorithm.\\As can be seen in Figure 3 the raw GPS positions are matched
to road segments after the application of the map matching algorithm.
\begin{figure}[h!]
\centering
\includegraphics[width=1\textwidth]{figures/urban.png}
\caption{Map Matching}
\label{fig:mm}
\end{figure}
At the moment fuzzyMM only works for \texttt{SpatialPointsDataFrame}
objects which contain the GPS positions of the track and GPS data such
as HDOP, speed and bearing. Since all of this is also included in the
\texttt{Track} class, it should be no problem to modify the function to
work with the trajectory classes.
\section{Conclusion}\label{conclusion}
As can be seen in the previous sections, what we can do with the
enviroCar data in R until now is mostly basics. We can load enviroCar
tracks into R, where they are represented by the classes from the
trajectories package and we can also do some basic plotting and
aggregate measurements of a Track object.
So there are several things that could be done in the future and maybe
in the scope of this course. This, for example, includes implementing
map matching to assign trajectories to road segments. Other things to
think about are aggregation methods, e.g.~the aggregation over multiple
trajectories or aggregation over space and/or time. What may be also
important and interesting is comparing trajectories of one driver and
also comparing trajectories between different drivers.
\section*{References}\label{references}
\addcontentsline{toc}{section}{References}
Gorte, Nikolai. 2014. \emph{fuzzyMM: Map Matching Using Fuzzy Logic}.
\url{http://CRAN.R-project.org/package=fuzzyMM}.
Pebesma, Edzer. 2012. ``spacetime: Spatio-Temporal Data in R.''
\emph{Journal of Statistical Software} 51 (7): 1--30.
\url{http://www.jstatsoft.org/v51/i07/}.
Pebesma, Edzer, and Benedikt Klus. 2014. \emph{trajectories: Classes and
Methods for Trajectory Data}.
\url{http://CRAN.R-project.org/package=trajectories}.
Pebesma, Edzer, Christoph Stasch, and Jan Wirwahn. 2014.
\emph{enviroCaR: Analysis of Car Trajectories Provided by EnviroCar
Project}. \url{https://github.com/enviroCar/enviroCaR}.
R Core Team. 2014. \emph{R: A Language and Environment for Statistical
Computing}. Vienna, Austria: R Foundation for Statistical Computing.
\url{http://www.R-project.org/}.
Wickham, Hadley, and Winston Chang. 2014. \emph{devtools: Tools to Make
Developing R Code Easier}.
\url{http://CRAN.R-project.org/package=devtools}.
\end{document}