Skip to main content

PySnapping

Snap points to a line string keeping a given order or spacing intact.

The PySnapping python library helps to solve the problem of snapping an ordered sequence of points to a line string, respecting the given input order.

The motivation for this library is to solve the problem of snapping stops onto vehicle trajectories in the GTFS format with inaccurate or missing kilometrage.

In order to be able to work with metric parameters and to treat data with large extent located anywhere on the world, we use the EPSG:4978 Cartesian 3D geocentric coordinate system for the internal representation.

The library aims to automatically classify kilometrage information as trusted or untrusted. Trusted points are always snapped as given by the kilometrage. In between trusted points, untrusted points are snapped by minimizing the sum of square snapping distances among all admissible solutions within certain radii. Admissible solutions are those that respect the order and minimum spacing between points.

Installation

Add the latest stable release from PyPI to your project with uv:

uv add pysnapping

Modules

Linear Referencing

The pysnapping.linear_referencing module contains low-level classes and functions for referencing points along linear features in N-dimensions built on top of numpy. This contains interpolation/extrapolation along a line string and data structures optimized for projecting points to substrings of a line string.

Utils

The pysnapping.util module contains common helper functions used in other parts of the library.

Snapping

The pysnapping.snap module is the main entry point for users of the pysnapping library and provides the classes needed to use the library.

Statistics

The pysnapping.stats module provides tools to aggregate statistics about snapping failures and the methods used in case of success.

Usage

The typical usage pattern is to create a pysnapping.snap.DubiousTrajectory instance which represents a vehicle trajectory with dubious kilometrage and a pysnapping.snap.DubiousTrajectoryTrip dtrip which represents a trip along such a trajectory with dubious kilometrage for the stops. Then dtrip.to_trajectory_trip can be used to get a pysnapping.snap.TrajectorTrip trip with well defined metric kilometrage. trip.trajectory then refers to a pysnapping.snap.Trajectory instance with well defined metric kilometrage.

The trip.snap_trip_points method can be used to snap the trip points onto the trajectory, resulting in a pysnapping.snap.SnappedTripPoints instance snapped. Then you can e.g. split the trajectory at the stops using the snapped.get_inter_point_ls_coords_in_travel_direction method. Snapping can be controlled with parameters given by a pysnapping.snap.SnappingParams instance.

A more detailed usage example (e.g. how to process GTFS input) is planned but not available yet. Until then, please also check the docstrings and source code for additional usage hints/possibilities.

Issue Tracker

Please use the GitHub issue tracker to report bugs/issues.

Development

Contributing

If you want to contribute to the pysnapping library, you can make a pull request at GitHub. Before working on major features/changes, please consider contacting us about your plans. See our GitHub page for contact details.

Editable Installation

Clone this repo and enter the corresponding directory. Then run:

uv sync

Pre-Commit Hooks

Enable pre-commit hooks:

uv run pre-commit install

From time to time (not automated yet) run

uv run pre-commit autoupdate

to update frozen revs.

Run Tests

Run tests and analyze code coverage:

uv run pytest --cov=pysnapping --cov-report term --cov-fail-under=85 pysnapping

Build release for PyPI

Make sure to add a git tag first and push it to geOps gitlab and github.

Install build once:

uv tool install build

Then run

pyproject-build

Changelog

v0.2.0

Breaking Changes

  • Snapping for untrusted points is now done by an exact algorithm instead of the iterative approximate solution. This implies breaking changes to the parameters in snap.SnappingParams as well as to parts of the API of the classes in the snap module. For example: Timing information to guide the initial conditions of the iterative solution is not necessary and thus not supported any more.
  • The ordering module has been removed since it is not needed any more.

Other Changes:

  • The development toolchain now uses ruff where possible.

Metadata

Release files for pysnapping 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysnapping 0.2.4
File Size Uploaded Provenance Actions
pysnapping-0.2.4.tar.gz 87.0 kB Without provenance Details for pysnapping-0.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pysnapping 0.2.4
File Interpreter ABI Platform Actions
pysnapping-0.2.4-py3-none-any.whl Python 3 none any Details for pysnapping-0.2.4-py3-none-any.whl

Total release size: 127.0 kB

Release files / pysnapping-0.2.4.tar.gz

Download URL pysnapping-0.2.4.tar.gz
Size 87.0 kB
Tags Source
SHA-256 checksum
How to use checksums
137fdcb83651a31808ad36e0f83c3ffab993728a98095a928399c4b077e81e5e
BLAKE2b-256 checksum
How to use checksums
67844c433091ba3c97d4cd82374a4fcd1873766e44f325aed35d2f575ae3bdbc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / pysnapping-0.2.4-py3-none-any.whl

Download URL pysnapping-0.2.4-py3-none-any.whl
Size 40.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d781f04a7a29957db46238d203f74669e90af8daace190425f6bc216ca65cea6
BLAKE2b-256 checksum
How to use checksums
73dc395dc89f16a439ee7f0d54dd8373ded55c80f33fe02dadd07b1ea09d0075
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Security for pysnapping 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page