Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can plot the match results using mmviz.plot_map, but matcher.path_pred_onlynodes is empty. #46

Open
Isigned opened this issue Apr 21, 2023 · 3 comments

Comments

@Isigned
Copy link

Isigned commented Apr 21, 2023

After using mmviz.plot_map, the route matching result map is already drawn.
However, when I want to further observe which routes are matched to the road network, I found that matcher.path_pred_onlynodes is empty.
How can I check which routes of the network are matched?

@wannesm
Copy link
Owner

wannesm commented Apr 21, 2023

That sounds odd, yes. Do you have a minimal working example that shows this behavior? Is matcher.path_pred also empty?

@Isigned
Copy link
Author

Isigned commented Apr 21, 2023

That sounds odd, yes. Do you have a minimal working example that shows this behavior? Is matcher.path_pred also empty?

Sorry, I checked later and found that mmviz.plot_map only draws the latitude and longitude of the trip, but does not match the route network information.

This code is from a post on the web that I refer to.

First set the boundary according to the latitude and longitude

import osmnx as ox
bounds =  [ ]  # Here are the latitude and longitude of two points, which represent a rectangular area
north, south, east, west = bounds[3], bounds[1], bounds[2], bounds[0]
G = ox.graph_from_bbox(north, south, east, west, network_type='drive')

Then get the coordinates of the road center point

nodes, edges = ox.graph_to_gdfs(G, nodes=True, edges=True)
edges['lon'] = edges.centroid.x
edges['lat'] = edges.centroid.y

Convert the coordinate system of the road network

G_p = ox.project_graph(G, to_crs=2416)
nodes_p, edges_p = ox.graph_to_gdfs(G_p, nodes=True, edges=True)

Convert the road network into a network

map_con = InMemMap(name='pNEUMA', use_latlon=True, use_rtree=False, index_edges=True)

Build the network

for node_id, row in nodes_p.iterrows():
    map_con.add_node(node_id, (row['y'], row['x']))
for node_id_1, node_id_2, _ in G_p.edges:
    map_con.add_edge(node_id_1, node_id_2)

Introduce the package

import geopandas as gpd

where "tmp_gdf" is a table with latitude and longitude, and finally "path" is a list with a tuple of travel latitude and longitude

tmp_gdf['geometry'] = gpd.points_from_xy(tmp_gdf['lat'],tmp_gdf['long'])
tmp_gdf = gpd.GeoDataFrame(tmp_gdf)
tmp_gdf.crs = {'init':'epsg:4326'}
tmp_gdf = tmp_gdf.to_crs(4326)

path = list(zip(tmp_gdf.geometry.y, tmp_gdf.geometry.x))

Matching

matcher = DistanceMatcher(map_con, 
                          max_dist=500, 
                          max_dist_init=170, 
                          min_prob_norm=0.0001,
                        non_emitting_length_factor=0.95,
                        obs_noise=50, 
                          obs_noise_ne=50,
                              dist_noise=50,
                              max_lattice_width=20,
                              non_emitting_states=True)

states, _ = matcher.match(path, unique=False)

fig, ax = mmviz.plot_map(map_con, matcher=matcher,
               show_labels=False, show_matching=True,show_graph=True,
               #figwidth=20,
               #use_osm=True, zoom_path=True,
              
               #lon_labels_right=True, lat_labels_bottom=True, flip_lon=True, flip_lat=True,
               filename=None)

mmviz.plot_map only draws the latitude and longitude of the trip, but does not match the route network information.

@wannesm
Copy link
Owner

wannesm commented Apr 23, 2023

You can activate debug output to see (and share) what is happening: https://leuvenmapmatching.readthedocs.io/en/latest/usage/debug.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants