Skip to content

Instantly share code, notes, and snippets.

@joaofig
Last active July 2, 2023 10:37
Show Gist options
  • Select an option

  • Save joaofig/cd142855bb60eaf6aef15ecec6c2eb22 to your computer and use it in GitHub Desktop.

Select an option

Save joaofig/cd142855bb60eaf6aef15ecec6c2eb22 to your computer and use it in GitHub Desktop.
The main map-matching data processing loop.
def main():
tiles = './valhalla/custom_files/valhalla_tiles.tar'
config = get_config(tile_extract=tiles, verbose=True)
max_traj_id = get_max_traj_id()
max_match = get_max_match()
for traj_id in range(max_match + 1, max_traj_id + 1):
actor = Actor(config)
print(traj_id)
try:
traj_df = load_trajectory_points(traj_id)
geometry = map_match(actor, traj_df)
insert_geometry(traj_id, geometry)
if geometry is not None:
line = decode_polyline(geometry)[1:-1]
hex_list = [h3.geo_to_h3(lat, lng, 15) for lng, lat in line]
insert_h3(traj_id, hex_list)
insert_h3_nodes(list(zip(hex_list, line)))
triples = generate_triples(hex_list)
if len(triples):
insert_triples(traj_id, triples)
except RuntimeError as e:
insert_error(traj_id, str(e))
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment