arthurdjn / noiseplanet

A Python package for Map Matching and Mapping. Research work for Noise Planet center.
http://noise-planet.org/
Apache License 2.0
51 stars 13 forks source link

Index is out of bounds #13

Open jks-liu opened 2 years ago

jks-liu commented 2 years ago
import numpy as np
from noiseplanet.matcher.model.route import route_from_track, graph_from_track
from noiseplanet.matcher import matching
import pandas as pd

track = np.array([[22.268942156, 114.184837977],
[22.26886763, 114.184626828],
[22.26876443, 114.184181684],
[22.268763939, 114.184155534],
[22.268766766, 114.184134369],
[22.268774784, 114.184118914],
[22.268783376, 114.184106381],
[22.268798513, 114.184089471],
[22.26892887, 114.18396158],
[22.269265791, 114.183630446],
[22.269747789, 114.183162936],
[22.270157877, 114.182682855]])
graph = matching.model.graph_from_track(track)
track_coor, route_corr, edgeid, stats = matching.match(graph, track, method='hmm')

error:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-1-b90d1030b8a8> in <module>
     17 [22.270157877, 114.182682855]])
     18 graph = matching.model.graph_from_track(track)
---> 19 track_coor, route_corr, edgeid, stats = matching.match(graph, track, method='hmm')

~/nb/p/py/noiseplanet/noiseplanet/matcher/matching.py in match(graph, track, method)
     61         track_corr, route_corr, edgeid, stats = model.match_nearest_edge(graph, track)
     62     elif method == 'hmm':
---> 63         track_corr, route_corr, edgeid, stats = model.match_leuven(graph, track)
     64     return track_corr, route_corr, edgeid, stats
     65 

~/nb/p/py/noiseplanet/noiseplanet/matcher/model/leuven.py in match_leuven(graph, track)
    123         lon_corr.append(lon)
    124 
--> 125         _, _, distance = geod.inv(track[idx][1], track[idx][0], lon, lat)
    126         proj_dist[idx] += distance
    127 

IndexError: index 12 is out of bounds for axis 0 with size 12

PS: Origin issue is from user @1213314896

https://github.com/arthurdjn/noiseplanet/issues/11#issuecomment-1003295828

jks-liu commented 2 years ago

Root cause for this issue is: One GPS points will match more than one points in the road graph.

Some GPS points are too far, so that the road the belong to are not adjacent, so some points (road) are added on the fly to make match roads are all adjacent.

Rajjat commented 2 years ago

I am facing the same issue. Did you find any solution?

jks-liu commented 2 years ago

I'll post a solution in few days.

pimakshay commented 2 years ago

This solution was published by the author @arthurdjn By adding the two lines of code, the index out of bound issue can be solved. Please correct me if I am wrong! ++++++++++++++++++++++++++ Ok, I found the error. It seems it is a particular case of the map. The last GPS point is near two good candidates, thus they are both kept in leuven package which leads to an error in the indexing.

If you want to update the code to handle this specific case, you just need to add two extra lines at noiseplanet/matcher/model/leuven.py, line 121:

for idx, m in enumerate(lat_nodes):
+   if idx >= len(track):
+       break
    lat, lon = m.edge_m.pi[:2]
    lat_corr.append(lat)
    lon_corr.append(lon)

This is some crappy code and won't update the git repository, at least for now. I need to rearrange the whole project, but as it is old I don't have the courage to clean and update it.

jks-liu commented 2 years ago

@pimakshay The solution can walk around the "index out of bound" error. However the result turns out to be a little bit wrong. Result index are mismatched.

lixian66670 commented 2 years ago

@jks-liu Hi,I am facing the same issue. Did you find any solution?Looking for your message!!!