Read, process, validate, match public transport stop data from different sources.
Project description
stoPTools Python package
The stoPTools Python package provides functions for processing public transport stop data from different sources, including data provided by the German DELFI e.V., PTSA and OpenStreetMap. The package provides routines for
- reading stop data from DELFI ZHV, GTFS feeds, PTSA,
- writing stop data to JSON files,
- validation of DELFI ZHV data,
- validation of GTFS data with focus on typical issues of the DELFI GTFS feed,
- matching stops from different sources.
There're additional scripts (not part of the actual Python package) for
- bulk downloading and processing data from multiple sources,
- viewing processed data on a map,
- matching stops from DELFI ZHV, GTFS, PTSA (API demo only).
The main branch holds the most recent release. The dev branch holds current (usable) state of development.
Install
Run
pip install stoptools
to install the package.
If you want to use the additional scripts, clone the repo and (optionally) do an editable install:
git clone https://codeberg.org/openPTdata/stoPTools.git
pip install -e ./stoPTools
Usage of update_all.py script
The update_all.py script downloads public transport stop data from different sources and converts the data to JSON files. Steps to follow:
- Rename
update_config.json.templatetoupdate_config.json. Theupdate_all.pyscript will read configuration from this file. - Adapt values in
update_config.jsonto your needs. Some hints:skip_providersis a list of data provider names to skip. Thus, you may have more providers in your config file than you actually use.providersis a list of data provider definitions:urleither is the direct URL to a ZIP archive containing the data or it's the URL of an HTML file containing a link to the ZIP archive. In the latter case seturl_regexto a regular expression for extracting the ZIP archive's URL from the HTML code (escape special characters to get a valid JSON string).zip_pathis a directory the downloaded ZIP file will be written to.json_pathis a directory the processed data will be written to.subsetsis a list of subset definitions. For each subset a separate JSON file will be generated. A subset definition is a tuple of subset name, subset type, subset parameters. Valid subset types areall(include all data),bbox(only include data within a bounding box),auth(provider typezhvonly; only include data from a specified authority). Forbboxsubset type the subset parameter is a list of four floats (south, west, north, east boundary of the box in degrees). Forauthsubset type the subset parameter is a string specifying the authority of interest.- For provider type
ptsayou have to specify PTSA regions to download data for and you have to provide an Overpass API instance. Don't use public Overpass API instances because theupdate_all.pyscript will download all public transport stop related data of the chosen regions in several quite large requests.
- Run
python update_all.pyand wait till finished.
Usage of viewer.py script
The viewer.py script generates MBTiles and a Leaflet map from processed data (JSON files). Steps to follow:
- Use the stoPTools package to generate JSON files with stop data.
- Rename
viewer_config.json.templatetoviewer_config.json. Theviewer.pyscript will read configuration from this file. - Adapt values in
viewer_config.jsonto your needs. Some hints:tmp_pathwill hold temporary files (GeoJSON and MBTiles) during tile generation. You have to manually delete those files. Depending on your data sources this directory may take several GB of disk space.html_pathis where generated HTML files go to. This should be a directory on a (local) web server.tiles_pathis where the MBTiles file goes to. This file contains all data (vector tiles) to show on the map and has to be accessible by your tile server (see next item).tiles_urlis where Leaflet finds the map tiles to render. You need a tile server to serve the generated MBTiles file's contents under this URL. A good choice is Martin. See Martin Tile Server Documentation for install instructions.skip_datais a list of data item IDs to skip. Thus, you may have more data items in your config file than you acutally use.datais a list of data source configurations including source file, colors aso.wms_layersis a list of aerial imagery sources to add to the map.
- Run
python viewer.pyand wait till finished. - Start your tile server with the generated MBTiles file.
- Load the generated HTML file in your web browser (via your web server to avoid problems with CORS).
Usage of match_demo.py script
The match_demo.py script calls various API functions to match stops from DELFI ZHV, (DELFI) GTFS and PTSA. It also contains some code for statistics and post-processing. Matching is done in four steps:
- prematching (normalize data obtained from different sources and collect possible matches),
- scoring (compute a score for each prematched stop pair and each attribute),
- total scores (aggregate attribute scores to one score per stop pair),
- grouping (group stops by total score if total score is above a minimum score).
Steps to follow:
- Use the stoPTools package to generate JSON files with stop data.
- Rename
match_demo_config.json.templatetomatch_demo_config.json. Thematch_demo.pyscript will read configuration from this file. - Adapt values in
match_demo_config.jsonto your needs. Some hints:prematchallows to skip the prematching step (iffalse) to save computation time if several scoring variants shall be tested.match_data_pathandmatch_scores_pathpoint to CSV files to store prematching and scoring results in. Setprematchtotruethe first time you run the script to create the CSV files.
- Run
python match_demo.py.
Contributing
Contributions welcome!
To contribute code please open a pull request. To report a bug or to propose an enhancement please file an issue.
See below for contact details of the package maintainer.
License
stoPTools is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the license, or any later version.
Contact and Support
The package is developed and maintained by Jens Flemming.
Feel free to reach out to the developer if you need assistance. Basic documentation may be found in the source code.
For bug reports and enhancement proposals please use the issue tracker.
Funding
Development of this Python package started when the author was head of the VeriBus project. VeriBus was a government-funded project at Zwickau University of Applied Sciences. Funding was provided by the German Federal Ministry of Transport from 2024 till 2026. Development now is based at Hochschule für Technik und Wirtschaft Dresden - University of Applied Sciences.
For legal reasons, we state the following funding information in German:
Das Projekt VeriBus wird im Rahmen der Innovationsinitiative mFUND mit insgesamt 158.464,31 Euro durch das Bundesministerium für Verkehr gefördert.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stoptools-0.1.0.tar.gz.
File metadata
- Download URL: stoptools-0.1.0.tar.gz
- Upload date:
- Size: 237.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77fcb8c4de921547a48b8f100fb96a6d6a258cb21788cdb740c920158f0fde5e
|
|
| MD5 |
27188edff35b36eba4681ee7326a793b
|
|
| BLAKE2b-256 |
56044637822e65f7a817d1e7431862cdcdf17f91b52f27bb5d0bfe91b13e8cbb
|
File details
Details for the file stoptools-0.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: stoptools-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 75.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
719645da105727af86e955146c234e962a31c9ecd2f107331362863f293862fa
|
|
| MD5 |
d9e8be1e8bd8e09755fc3c6e3ad55329
|
|
| BLAKE2b-256 |
f5dbeb7f8b7a783e5bb46d7c0e3891b79eee4bbb0c989f050a5dceff388172ca
|