wannesm / LeuvenMapMatching

Leuven.MapMatching toolbox for aligning GPS measurements to locations on a map.
Other
222 stars 43 forks source link

How to exclude the first/last edges from the match if they have only a small overlap with the source trajectory? #47

Open lukasballo opened 1 year ago

lukasballo commented 1 year ago

How can we exclude the nodes 8 and/or 6 from the result if only a small portion of the edges 8-2 and 5-6 overlaps with the source trajectory? E.g., enforcing an overlap of >90%, otherwise removing these nodes from the result?

Thanks for any ideas!

matcher = DistanceMatcher(map_con)
matcher.match(path)
nodes = matcher.path_pred_onlynodes
# result: [8, 2, 1, 5, 6]

match_plot

wannesm commented 1 year ago

This could be possible but requires changing the inner workings of the matcher (the initial search has an argument to use edges or not, but it is not exposed).

In post-processing, however, this would be easier. You can inspect the found path and see how close the match is to the vertex. Either by computing the distance or by checking the relative distance wrt the edge (0 and 1 are the two ends of the edge). For example, for the first observation O0, this is available as

if matcher.lattice_best[0].edge_m.ti < 0.1:
    print(f'Close to node: {matcher.lattice_best[0].edge_m.l1}
elif matcher.lattice_best[0].edge_m.ti > 0.9:
    print(f'Close to node: {matcher.lattice_best[0].edge_m.l2}
else:
    print('Node not close to a vertex')

The distance between the interpolated point and the end of the edge would be:

map_con.distance(matcher.lattice_best[0].edge_m.pi, matcher.lattice_best[0].edge_m.p1)