Closed Laura0106 closed 3 years ago
Hello !
It looks like there is an issue with the indexes.
Maybe it is the graph that do not have enough points, or maybe your track.
Can you please try the method='nearest'
method to see if it works ?
Also, is it possible to have some of your data samples so I can reproduce this error ?
https://colab.research.google.com/drive/184UWW4xIOUlP8Gi7bPlM6_76VWOAlcsp?usp=sharing
I am sharing with my google colab notebook, where I use this data sample (where this error happens). You can just run it
Thank you ! Will be glad for any feedback!
with method='nearest'
it works, but I really need to use method='hmm'
Generally , I would like to put whole trip into graph (for ex osmnx). To be more precise : for each GPS point there should be closest edge (of the graph) , from that I can plot whole trip with the help of these edges. (like in the photo:
when I use noiseplanet with method = "hmm"
it, returns list of these edges (osmnx) , so I plot these edges and get result what I am working for 3 months. (in the photo)
Thank you for the colab, it really helped me to debug the code 👍🏻
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.
Finally, to easily plot your maps / routes, you can use:
# Plot the graph
fig, ax = ox.plot_graph(graph, show=False, close=False)
# Plot the track
ax.plot(track[:, 1], track[:, 0], color="red")
# Plot the route
ax.plot(track_corr[:, 1], track_corr[:, 0], color="green")
Thank you a lot! Your help was vital for my project! Now, I am receiving list with edges in correct order. Can I plot it into folium map ?
Glad I solved your issue, and good luck for your master thesis !
Hmmm, I guess you can use the plot_html
function for this specific case.
If your initial issue is solved, I will close it 😉
Yes, now it works correctly. Just a small question, Is it possible to build whole network street for one place using noiseplanet ? I would like to put my track , which consist of edges returned by noiseplanet to this network street. Like in the photo. In the photo blue color - are edges, purple - nodes , black - my track
What do you mean by building the whole network street ?
Currently, noiseplanet
does not have functions to build a network. It only matches a GPS track to an existing graph.
What it can do, is match multiple GPS tracks to an already existing network.
track_coor, route_corr, edgeid, stats = matching.match(graph, track, method='hmm')
ok, in this code can I put as graph
, graph , which is build by osmnx?
POINT = 54.252771, 13.027689 # center of the trip AO = 8000 # area of observation
G = ox.graph_from_point(POINT, network_type="drive", dist=AO, simplify=False, retain_all=True, truncate_by_edge=True,)
Yes you can, the graph used in matching.match(...)
comes from osmnx
I am trying to use osmnx graph in the code matching.match(...)
But returns me error : " Exception: Did not find a matching node for path point at index 20"
The code :
POINT = 54.252771, 13.027689 # center of the trip
AO = 8000 # area of observation
G = ox.graph_from_point(POINT, network_type="drive", dist=AO, simplify=False, retain_all=True, truncate_by_edge=True,)
track_coor, route_corr, edgeid, stats = matching.match(G, track, method='hmm')
will be glad for any feedback! Thank you!
For this one the issue is not related to noiseplanet
but osmnx
.
The following code returns:
G = ox.graph_from_point((54.252771, 13.027689), network_type="drive", dist=AO, simplify=False, retain_all=True, truncate_by_edge=True)
You need to increase a bit your search radius, for example with dist=10_000
:
You can also use a bounding box to be sure of the geographic extent you need to retrieve (i.e. the city's extent):
bbox = (54.392607, 54.104256, 13.260138, 12.713013)
G = ox.graph_from_bbox(*bbox, network_type="drive", simplify=False, retain_all=True, truncate_by_edge=True)
ok , thanks a lot!
Can I ask one more question! I am so sorry for bothering you.
I implented code:
POINT = 54.252771, 13.027689 # center of the trip
AO = 12000 # area of observation
G = ox.graph_from_point(POINT, dist = AO, network_type="drive", simplify=False, retain_all=True, truncate_by_edge=True)
track_coor, route_corr, edgeid, stats = matching.match(G, track, method='hmm')
Then I recieved list of edges (each edges consist of 2 node IDs) from edgeid
Then I tried to visualize
for i in dup_free: map_ = ox.plot_route_folium(G, i, route_map = graph_map, route_color = 'black', route_width= 7)
where dup_free
is list of edges (each edges consist of 2 node IDs)
But I recieve this error : "KeyError: 5302998390"
I tried to run your colab but did not have this issue.
Maybe it is because one of the node 5302998390
is not in the graph. Don't really know why but it looks like it is an error from osmnx
.
If you just want to run your code and don't care if the node 5302998390
is missing, you can use:
for edge in dup_free:
try:
map_ = ox.plot_route_folium(G, edge , route_map=graph_map, route_color='black', route_width=7)
except KeyError as error:
print(f"WARNING: The edge {edge} was not added: {error}")
If your objective is only to display your track on a leaflet map, I would suggest you to directly use the Leaflet API. It provides javascript tool to show multiple geographic objects. To do that, you will need:
PS: I closed this issue as it is no longer related to the original one. If you have another issue, please create a new thread so it will be easier to manage them. Anyway, good luck with your project !
Hello dear developers! Thank for your work! I am trying to implement noiseplanet in my master thesis. I tried to use noiseplanet.matcher.matching.match(graph, track, method='hmm') to receive nearest edges for GPS points. While using this package I get this error "IndexError: index 29 is out of bounds for axis 0 with size 29". Could you help with that? Thanks in advance