MovingPandas.TrajectoryGeneralizer

movingpandas: Implementation of Trajectory classes and functions built on top of GeoPandas

class movingpandas.TrajectoryGeneralizer(traj)

Generalizer base class

__init__(traj)

Create TrajectoryGeneralizer

Parameters

traj (Trajectory or TrajectoryCollection) –

generalize(tolerance)

Generalize the input Trajectory/TrajectoryCollection.

Parameters

tolerance (any type) – Tolerance threshold, differs by generalizer

Returns

Generalized Trajectory or TrajectoryCollection

Return type

Trajectory/TrajectoryCollection

class movingpandas.DouglasPeuckerGeneralizer(traj)

Generalizes using Douglas-Peucker algorithm (as implemented in shapely/Geos).

tolerancefloat

Distance tolerance in trajectory CRS units

References

  • Douglas, D., & Peucker, T. (1973). Algorithms for the reduction of the number of points required to represent a digitized line or its caricature. The Canadian Cartographer 10(2), 112–122. doi:10.3138/FM57-6770-U75U-7727.

Examples

>>> mpd.DouglasPeuckerGeneralizer(traj).generalize(tolerance=1.0)
class movingpandas.MinDistanceGeneralizer(traj)

Generalizes based on distance.

This generalization ensures that consecutive locations are at least a certain distance apart.

Distance is calculated using CRS units, except if the CRS is geographic (e.g. EPSG:4326 WGS84) then distance is calculated in metres.

tolerancefloat

Desired minimum distance between consecutive points

Examples

>>> mpd.MinDistanceGeneralizer(traj).generalize(tolerance=1.0)
class movingpandas.MinTimeDeltaGeneralizer(traj)

Generalizes based on time.

This generalization ensures that consecutive rows are at least a certain timedelta apart.

tolerancedatetime.timedelta

Desired minimum time difference between consecutive rows

Examples

>>> mpd.MinTimeDeltaGeneralizer(traj).generalize(tolerance=timedelta(minutes=10))
class movingpandas.TopDownTimeRatioGeneralizer(traj)

Generalizes using Top-Down Time Ratio algorithm proposed by Meratnia & de By (2004).

This is a spatiotemporal trajectory generalization algorithm. Where Douglas-Peucker simply measures the spatial distance between points and original line geometry, Top-Down Time Ratio (TDTR) measures the distance between points and their spatiotemporal projection on the trajectory. These projections are calculated based on the ratio of travel times between the segment start and end times and the point time.

tolerancefloat

Distance tolerance (distance returned by shapely Point.distance function)

References

  • Meratnia, N., & de By, R.A. (2004). Spatiotemporal compression techniques for moving point objects. In International Conference on Extending Database Technology (pp. 765-782). Springer, Berlin, Heidelberg.

Examples

>>> mpd.TopDownTimeRatioGeneralizer(traj).generalize(tolerance=1.0)