Map Matching

Fast Map Matching (FMM) Module

class mtldp.mtltrajs.FmmModule(map_folder, shapefile_folder, load_map=False)
__init__(map_folder, shapefile_folder, load_map=False)
Parameters
  • map_folder

  • shapefile_folder

  • load_map

run(input_file, output_file)
Parameters
  • input_file

  • output_file

Returns

mtldp.mtltrajs._output_trajs_for_fmm(df, output_file, min_latitude, max_latitude, min_longitude, max_longitude)

create input file (csv) for fast map matching from a dataframe of trajectory points

Filter dataframe and add an “integer id” attribute to prepare for fast map matching result integration (mtldp.mtltrajs._load_fmm_results)

Parameters
  • df – dataframe of trajectory points with the following attributes: longitude, latitude, and timestamp

  • output_file (str) – path name for the fmm input file

  • min_latitude (float) – minimum latitude of bounding box

  • max_latitude (float) – maximum latitude of bounding box

  • min_longitude (float) – minimum longitude of bounding box

  • max_longitude (float) – maximum longitude of bounding box

Returns

filtered dataframe of trajectory points inside bounding box and added ‘integer id’ attribute

mtldp.mtltrajs._load_fmm_results(df, fmm_mr_file, debug=False)

match output file from fast map matching with the filtered dataframe of trajectory points

Parameters
  • df – filtered dataframe of trajectory points inside map matching bounding box created in mtldp.mtltrajs._output_trajs_for_fmm

  • fmm_mr_file (str) – path name of fast map matching output file

  • debug (bool) – special mode for debugging (in development)

Returns

same dataframe of trajectory points with the following added attributes:

'segment_id': edge matched to each point in trajectory
'error': distance from each point to its matched point
'offset': distance from the matched point to the start of the matched edge
Debug Mode:
'latitude_match': matched latitude coordinate
'longitude_match': matched longitude coordinate
'point_path': list of edges traversed since last point
'emission_prob': emission probability
'transition_prob': transition probability

Map Attribute Matching

mtldp.mtltrajs.add_map_attributes(df, network)

Add essential mapping information from the network (mtldp.mtlmap.Network) to each trajectory point

runs both the add_basic_attributes and add_movement_info functions to add both basic attributes and movement info

Parameters
Returns

dataframe of trajectory points with the following map attributes:

{'upstream_intersection': upstream intersection id,
'downstream_intersection': downstream intersection id,
'link_id': link id,
'upstream_movement': upstream phase movement,
'downstream_movement': downstream phase movement}

mtldp.mtltrajs.add_basic_attributes(df, network)

Add basic mapping information from the network (mtldp.mtlmap.Network) to each trajectory point

Parameters
Returns

dataframe of trajectory points with the following map attributes:

{'upstream_intersection': upstream intersection id,
'downstream_intersection': downstream intersection id,
'link_id': link id}

mtldp.mtltrajs.add_movement_info(df, network)

Add movement info to each trajectory point

Parameters
Returns

dataframe of trajectory points with the following map attributes:

{'upstream_movement': upstream phase movement,
'downstream_movement': downstream phase movement}