Model¶
In trackintel, tracking data is split into several classes. It is not generally
assumed that data is already available in all these classes, instead, trackintel
provides functionality to generate everything starting from the raw GPS positionfix data
(consisting of at least (user_id, tracked_at, longitude, latitude, elevation, accuracy)
tuples).
- positionfixes: Raw GPS data.
- staypoints: Locations where a user spent a minimal time.
- triplegs: Segments covered with one mode of transport.
- trips: Segments between consecutive activities (special staypoints that are not just waiting points).
- customer movements: Sequences of triplegs which use only public transport.
- tours: Sequences of trips which start and end at the same place (if
journey
is set toTrue
, this place is home). - places: Clustered staypoints.
A detailed (and SQL-specific) explanation of the different classes can be found under Data Model (SQL).
Some of the more time-consuming functions of trackintel generate logging data, as well as extracted features data, and they assume more data about geographic features or characteristics of transport modes are available. These are not explained here yet.
GeoPandas Implementation¶
In trackintel, we assume that all these classes are available as (Geo)Pandas (Geo)DataFrames. While we do not extend the given DataFrame constructs, we provide accessors that validate that a given DataFrame corresponds to a set of constraints, and make functions available on the DataFrames. For example:
df = trackintel.read_positionfixes_csv('data.csv')
df.as_positionfixes.extract_staypoints()
This will read a CSV into a format compatible with the trackintel understanding of a collection of
positionfixes, and the second line will wrap the DataFrame with an accessor providing functions such
as extract_staypoints()
.
Available Accessors¶
The following accessors are available.
-
class
trackintel.model.positionfixes.
PositionfixesAccessor
(pandas_obj)¶ A pandas accessor to treat (Geo)DataFrames as collections of positionfixes. This will define certain methods and accessors, as well as make sure that the DataFrame adheres to some requirements.
Requires at least the following columns:
['user_id', 'tracked_at', 'elevation', 'accuracy', 'geom']
Examples
>>> df.as_positionfixes.extract_staypoints()
Attributes: center
Returns the center coordinate of this collection of positionfixes.
Methods
extract_staypoints
(*args, **kwargs)Extracts staypoints from this collection of positionfixes. extract_staypoints_and_triplegs
(*args, **kwargs)Extracts staypoints, uses them to build triplegs, and builds all associations with the original positionfixes (i.e., returning everything in accordance with the trackintel Data Model (SQL)). extract_triplegs
(*args, **kwargs)Extracts triplegs from this collection of positionfixes. plot
(*args, **kwargs)Plots this collection of positionfixes. to_postgis
(conn_string, table_name)Stores this collection of positionfixes to PostGIS.
-
class
trackintel.model.staypoints.
StaypointsAccessor
(pandas_obj)¶ A pandas accessor to treat (Geo)DataFrames as collections of staypoints. This will define certain methods and accessors, as well as make sure that the DataFrame adheres to some requirements.
Requires at least the following columns:
['user_id', 'started_at', 'finished_at', 'elevation', 'geom']
Examples
>>> df.as_staypoints.extract_places()
Attributes: center
Returns the center coordinate of this collection of staypoints.
Methods
extract_places
(*args, **kwargs)Extracts places from this collection of staypoints. plot
(*args, **kwargs)Plots this collection of staypoints.
-
class
trackintel.model.triplegs.
TriplegsAccessor
(pandas_obj)¶ A pandas accessor to treat (Geo)DataFrames as collections of triplegs. This will define certain methods and accessors, as well as make sure that the DataFrame adheres to some requirements.
Requires at least the following columns:
['user_id', 'started_at', 'finished_at', 'geom']
Examples
>>> df.as_triplegs.plot()
Methods
plot
(*args, **kwargs)Plots this collection of triplegs.
-
class
trackintel.model.places.
PlacesAccessor
(pandas_obj)¶ A pandas accessor to treat (Geo)DataFrames as collections of places. This will define certain methods and accessors, as well as make sure that the DataFrame adheres to some requirements.
Requires at least the following columns:
['user_id', 'geom']
Examples
>>> df.as_places.plot()
Methods
plot
(*args, **kwargs)Plots this collection of places.