Skip to content

Instantly share code, notes, and snippets.

Python packages for mobility data

Analysis of mobility data

  • MovingPandas implements a Trajectory class and corresponding methods based on GeoPandas.

Fokus on human mobility data

  • scikit-mobility is a library for human mobility analysis in Python.
  • trackintel is a library for the analysis of spatio-temporal tracking data with a focus on human mobility. The core of trackintel is the hierachical data model for movement data that is used in GIS, transport planning and related fields. We provide functionalities for the full life-cycle of human mobility data analysis: import and export of tracking data of different types (e.g, trackpoints, check-ins, trajectories), preprocessing, data quality assessment, semantic enrichment, quantitative analysis and mining tasks, and visualization of data and results.

Routing and travel time matrices

# A Script to
# - download the GeoLife (https://www.microsoft.com/en-us/research/publication/geolife-gps-trajectory-dataset-user-guide/) data
# - transform it to a .csv file
# - and cut records to given outlines
# not very performant bc of preprocessing with pandas (takes about 30 min)
# produces a 1,8 GB output csv file
import os
from pathlib import Path
# snap GPS trajectories to OSM road network
# expected csv format: tid,lon,lat
# where tid is the trip id, where all coordinates of the same trip share the same id
# the order of coordinates is expected to be in correct order
# setup OSRM server: https://hub.docker.com/r/osrm/osrm-backend/
import csv
import requests

How to add / edit an attribute in a OpenStreetMap (OSM) PBF file

OSM2psql is a handy tool for importing OSM data into a PostgreSQL database. Though, the created database cannot be converted back to a PBF file. For example, to use a routing algorithm (e.g., Graphhopper) with a custom weighting, the PBF format is needed. For this, I used Osmosis.

For the task of editing a PBF file and re-creating a new PBF file I used the following process:

1. Install PostgreSQL, PostGIS and Osmosis.