Package: pysnapping
PySnappingSnap 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 theGTFS formatwith 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 theEPSG:4978Cartesian 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.InstallationInstall the latest stable release from PyPI with pip:pipinstallpysnappingModulesLinear ReferencingThepysnapping.linear_referencingmodule contains low-level classes and functions for referencing points along
linear features in N-dimensions built on top ofnumpy. This contains interpolation/extrapolation along a line string
and data structures optimized for projecting points to substrings of a line string.UtilsThepysnapping.utilmodule contains common helper functions used in other parts of the library.SnappingThepysanpping.snapmodule is the main entry point for users of thepysnappinglibrary and
provides the classes needed to use the library.UsageThe typical usage pattern is to create apysnapping.snap.DubiousTrajectoryinstance which represents
a vehicle trajectory with dubious kilometrage and apysnapping.snap.DubiousTrajectoryTripdtripwhich represents
a trip along such a trajectory with dubious kilometrage for the stops.
Thendtrip.to_trajectory_tripcan be used to get apysnapping.snap.TrajectorTriptripwith well defined
metric kilometrage.trip.trajectorythen refers to apysnapping.snap.Trajectoryinstance with well defined metric
kilometrage.Thetrip.snap_trip_pointsmethod can be used to snap the trip points onto the
trajectory, resulting in apysnapping.snap.SnappedTripPointsinstancesnapped. Then
you can e.g. split the trajectory at the stops using thesnapped.get_inter_point_ls_coords_in_travel_directionmethod. Snapping can be
controlled with parameters given by apysnapping.snap.SnappingParamsinstance.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 TrackerPlease usethe GitHub issue trackerto report bugs/issues.DevelopmentContributingIf you want to contribute to the pysnapping library, you can make a pull request atGitHub.
Before working on major features/changes, please consider contacting us about your plans.
Seeour GitHub pagefor contact details.Editable InstallationClone this repo and enter the corresponding directory.
Create a virtual environment, then install frozen requirements, dev-requirements
and this library in editable mode:python3.9-mvenvenv
.env/bin/activate
pipinstall-Upip
pipinstall-rrequirements.txt-rdev-requirements.txt-e.Keep env activated for all following instructions.Pre-Commit HooksEnable pre-commit hooks:pre-commitinstallFrom time to time (not automated yet) runpre-commitautoupdateto update frozen revs.Run TestsRun tests and analyze code coverage:pytest--cov=pysnapping--cov-reportterm--cov-fail-under=85pysnappingChangelogv0.2.0Breaking ChangesSnapping for untrusted points is now done by an exact algorithm instead of the
iterative approximate solution. This implies breaking changes to the parameters insnap.SnappingParamsas well as to parts of the API of the classes in thesnapmodule. For example: Timing information to guide the initial conditions of the
iterative solution is not necessary and thus not supported any more.Theorderingmodule has been removed since it is not needed any more.Other Changes:The development toolchain now uses ruff where possible.