movingpandas.Trajectory.add_distance#
- Trajectory.add_distance(overwrite=False, name='distance', units=None)#
Add distance column and values to the trajectory’s DataFrame.
Distance values are computed between the current point and the previous:
If no units have been declared:
For geographic projections (e.g. EPSG:4326 WGS84), in meters
For other projections, in CRS units
If units have been declared:
For geographic projections, in declared units
For known CRS units, in declared units
For unknown CRS units, in declared units as if CRS is in meters
- Parameters:
overwrite (bool) – Whether to overwrite existing distance values (default: False)
name (str) – Name of the distance column (default: “distance”)
units (str) – Units in which to calculate distance values (default: CRS units) For more info, check the list of supported units at https://movingpandas.org/units
Examples
If no units are declared, the distance will be calculated in meters for geographic projections (e.g. EPSG:4326 WGS84) and in CRS units for all other projections
>>>traj.add_distance()
The default column name is “distance”. If a column of this name already exists, a new column name can be specified
>>>traj.add_distance(name=”distance (CRS units)”)
If units are declared, the distance will be calculated in those units except if the CRS units are unknown, in which case the CRS units are assumed to be in meters
>>>traj.add_distance(units=”km”)
It is suggested to declare a name for the new column specifying units
>>>traj.add_distance(name=”distance (miles)”, units=”mi”) >>>traj.add_distance(name=”distance (US Survey Feet)”, units=”survey_ft”)