GPS utilities

Utility functions with regard to the GPS coordinates

The valid degree is within (-180, 180]

Reference:

GSP to distance

mtldp.utils.haversine_distance(coord1, coord2)

Get the distance between two gps coordinates.

Parameters
  • coord1 (tuple) – GPS point 1 in tuple (lat, lon)

  • coord2 (tuple) – GPS point 2 in tuple (lat, lon)

Returns

distance in meters

mtldp.utils.get_trace_length(lat_list, lon_list)

Get the length of a trajectory data.

Parameters
  • lat_list – latitude list

  • lon_list – longitude list

Returns

lengths of the trajectory by meters

GPS to heading/angle

mtldp.utils.get_directed_segment_heading(start_coord, end_coord)

Calculate the heading of a directed line segment.

Use cosine approximation, if the distance between the two points is too large, then this will not give you the write output

Parameters
  • start_coord (tuple) – GPS point 1 in tuple (lat, lon)

  • end_coord (tuple) – GPS point 2 in tuple (lat, lon)

Returns

heading from (-180, 180]

mtldp.utils.get_gps_trace_heading_info(lat_list, lon_list)

Get the heading angle given the lat and lon list.

Parameters
  • lat_list

  • lon_list

Returns

forward_heading, forward_weighted_heading, backward_heading, backward_weighted_heading

mtldp.utils.get_angle_difference(degree1, degree2)

Get the difference between two angle (the output is always less than 180)

Parameters
Returns

difference of the two angles

mtldp.utils.get_closest_angle(degree, degree_list)

Get the closest angle (return the index) among a set of options.

Parameters
  • degree

  • degree_list

Returns

mtldp.utils.reverse_degree(degree)

Get the reverse degree

Parameters

degree

Returns

GPS shift and segmentation

mtldp.utils.segment_gps_trace(lat_list, lon_list, split_into=10)

Split the gps trace evenly.

Parameters
  • lat_list

  • lon_list

  • split_into

Returns

mtldp.utils.shift_geometry(geometry, shift_distance=7, shift_direction='left')

Shift the geometry towards a certain direction.

Parameters
  • geometrymtldp.utils.Geometry

  • shift_distance (float) – meters

  • shift_direction (str) – "left" or "right"

Returns

mtldp.utils.get_shifted_gps_trace(lat_list, lon_list, shift_direction=0.0, shift_distance=20)

Shift the GPS trace towards a certain direction.

Parameters
  • lat_list

  • lon_list

  • shift_direction – shifting direction given by angle

  • shift_distance (float) –

Returns