简体   繁体   中英

Plotting a route on a given map on Python OSMNX

I have a dataframe that consists GPS data from a vehicle. It has longitude, latitude values with a timestamp on it. I want to visualize the route the car has been on a map.

OSMNX has a function 'plot_graph_route' and 'plot_graph_folium' which takes the route as a parameter but I could not figure out what kind of structure I should give.

I could not figure out what kind of structure I should give

The usage of plot_graph_route and the structure of its arguments are fully described in the OSMnx documentation . The technique to plot routes between lat-lng points is documented in the OSMnx examples , as follows:

origin_point = (37.792896, -122.412325)
destination_point = (37.790495, -122.408353)
origin_node = ox.get_nearest_node(G, origin_point)
destination_node = ox.get_nearest_node(G, destination_point)
route = nx.shortest_path(G, origin_node, destination_node, weight='length')
fig, ax = ox.plot_graph_route(G, route, origin_point=origin_point, destination_point=destination_point)

Both the documentation and the examples similarly describe the plot_graph_folium function.

OSMnx can plot the route on a map if the route comprises of OSM nodes with OSM ids.

What you have currently are raw GPS points comprising of a series of (lat,long) points. The first step should be map-matching, a procedure to map the GPS data points to the nearest/most appropriate OSM node. If you can do that for all your GPS data points, you will have the most appropriate OSM node/ point on the OSM road network (depending on how sophisticated your map-matching algorithm is) for each of your GPS data points.

OSMnx has a very coarse map-matching representation in terms of getting the nearest node for a given (lat,long) in the form of

origin_point = (37.792896, -122.412325)
origin_node = ox.get_nearest_node(G, origin_point)

as mentioned by Geoff in his answer. You may choose to do this for all your GPS data points instead of just the end points and retrieving the shortest route. But, then again, this is very coarse map-matching, depending on your desired accuracy.

So essentially, you should have a series of OSM node ids at the end of this exercise. If you pass those as the route parameter in ox.plot_graph_route, you should be able to produce the required visualisation of the 'possible' route.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM