wannesm / LeuvenMapMatching

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

doesn't return states and nodes #15

Open Laura0106 opened 3 years ago

Laura0106 commented 3 years ago

Hello dear developers! I am trying to use LeuvenMapMatching in my Master thesis. I am using the example with osmnx from documentation https://leuvenmapmatching.readthedocs.io/en/latest/usage/openstreetmap.html#using-osmnx-and-geopandas

I have created map_con, graph osmnx from the example. Then, transformed GPS Points to CRS which Project graph use. Then ,implemented code from example :

matcher = DistanceMatcher(map_con, max_dist=2, obs_noise=1, min_prob_norm=0.5)
states, _ = matcher.match(path)
nodes = matcher.path_pred_onlynodes

print("States\n------")
print(states)
print("Nodes\n------")
print(nodes)
print("")
matcher.print_lattice_stats()

But it doesn't return any "states" or "nodes"

Huzaifg commented 3 years ago

I am facing the same error for a similar setup

wannesm commented 3 years ago

This probably means no matching is found. If you projected to meters than the values 2 and 1 are quite small (e.g. noise of only 1m is expected). More realistic values would be around 50m.

You can increase the output by setting the logging level (using the logging module):

leuvenmapmatching.logger.setLevel(logging.INFO)  # or if you want to see all steps: logging.DEBUG
leuvenmapmatching.logger.addHandler(logging.StreamHandler(sys.stdout))  # add only if you don't see any output, otherwise it appears double
Huzaifg commented 3 years ago

Yes using the logger did help. I was able to obtain the states after playing around with the parameters. However, now I am currently facing another issue with the states. I am using the following code to get the edge ids

matcher = DistanceMatcher(map_con, max_dist=1000, max_dist_init=2000, # meter min_prob_norm=0.001, non_emitting_length_factor=0.75, obs_noise=10, obs_noise_ne=75, # meter dist_noise=10, # meter non_emitting_edgeid=False) edgeid, lastidx = matcher.match(path)

Here map_con is generated with the following code

# Creation of the Leuven Map object from the OSM network
    map_con = InMemMap("myosm", use_latlon=True, use_rtree=True, index_edges=True)
    # Add the OSM network into the Leuven Map object
    nodes_id = list(graph.nodes)
    for node in nodes_id:
        lat = graph.nodes[node]['y']
        lon = graph.nodes[node]['x']
        map_con.add_node(node, (lat, lon))
    edges_id = list(graph.edges)
    for edge in edges_id:
        node_a, node_b = edge[0], edge[1]
        map_con.add_edge(node_a, node_b)
        map_con.add_edge(node_b, node_a)

    map_con.purge()

I am getting edgeids for all of my 2000 GPS points. However , some edge ids do not match to any road in the graph obtained from open street network.

For example the point 19.136265,74.008378 is snapped to road with edge id 6038805371, 6038806293.

The graph I use is generated using osmnx with -

G = ox.graph_from_bbox(20.045204,18.569678,74.3,73.637611,network_type = 'drive')

and converted into a geodataframe using -

trip_nodes, trip_streets = ox.graph_to_gdfs(G)

trip_streets then is the following geodataframe - Screenshot 2021-06-30 at 11 37 55 AM

However, now when in try to index into trip_streets using u = 6038805371, v = 6038806293 , key = 0/1/2, I get a KeyError.

This happens in my case for 8 more roads given by edgeids 6038806293 , 6038792279 | 6038792279 6038792985 | 6038792985 6038792245 | 6038792245 6038792997 6038792997 6038792249 | 6038779847 6038779861 | 6038779861 6038779869 | 6038779869 2213151251

I wonder why this happens. My aim is to ultimately find the geometry of the edge onto which my GPS point has been projected for which I need to use the edgeids obtained from the function to index out the geometry from a OSM geodataframe.

Any help will be appreciated. Best

Edit 1 - Formated better