Skip to content

Instantly share code, notes, and snippets.

@joaofig
Created November 30, 2024 11:40
Show Gist options
  • Save joaofig/ca56e318a3d876fd4271289fc8bd7b74 to your computer and use it in GitHub Desktop.
Save joaofig/ca56e318a3d876fd4271289fc8bd7b74 to your computer and use it in GitHub Desktop.
Computes the GPS segment list for a map-matched trajectory and the corresponding map polyline
def compute_gps_segments(unique_df: pd.DataFrame,
polyline: np.ndarray) -> List[GpsSegment]:
traj = Trajectory(lat=unique_df["match_latitude"].to_numpy(),
lon=unique_df["match_longitude"].to_numpy(),
time=unique_df["time_stamp"].to_numpy() / 1000.0,
ids=unique_df["signal_id"].to_numpy())
map_tree = traj.merge(map_lat=polyline[:, 0], # Latitude
map_lon=polyline[:, 1]) # Longitude
gps_segments = map_tree.get_segments()
return gps_segments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment