Thanks for your interest in trackintel. This tutorial shows you the most important functionalities and walks you through a typical usecase. You can find additional information in the examples folder.
First, install trackintel using:
pip install trackintel
Test the install using:
import trackintel as ti ti.print_version()
This page focuses on setting the trackintel environment under a working PostGIS database; this will make data persistence a lot easier. For working with CSV files or Geopandas GeoDataframes, please check the trackintel_basic_tutorial or run it directly in MyBinder notebook .
If you decide to work with PostGIS, look at the set SQL script, which will create all necessary tables. Simply execute it within a new/empty database.
To get you started, we put some trajectory data (in the form of positionfixes) in the examples/data folder. You can import one of these by executing the following steps:
import trackintel as ti database_name = 'trackintel-tests' conn_string = 'postgresql://test:1234@localhost:5432/' + database_name pfs = ti.read_positionfixes_csv('examples/data/posmo_trajectory_2.csv', sep=';') pfs.as_positionfixes.to_postgis('positionfixes', conn_string, if_exists='append')
This will fill the positionfixes of
posmo_trajectory_2.csv into the table
positionfixes of the database
trackintel-tests. Make sure that you update the
connection string with your proper username and password.
We now can for example plot the positionfixes:
Of course, we can start our analysis, for example by detecting staypoints (aggregated positionfixes where the user stayed for a certain amount of time):
_, locs = pfs.as_positionfixes.generate_staypoints(method='sliding') sp.as_staypoints.plot(out_filename='staypoints.png', radius=10, positionfixes=pfs, plot_osm=True)
This will additionally plot the original positionfixes, as well as the underlying street network from OSM. We can for example continue by extracting and plotting locations (locations that “contain” multiple staypoints, i.e., are visited often by a user):
_, locs = sp.as_staypoints.generate_locations(method='dbscan', epsilon=100, num_samples=1) locs.as_locations.plot(out_filename='locations.png', radius=125, positionfixes=pfs, staypoints=sp, staypoints_radius=100, plot_osm=True)
This will extract locations and plot them to a file called
plotting the original positionfixes and staypoints, as well as the street network.
As you can see, in trackintel, everything starts with positionfixes. From these
you can generate
triplegs, which in turn can be aggregated into
trips. You can find the exact model description in the