Open vtao1989 opened 1 year ago
Sounds like a simple error handling in the for loop will solve your issue no? Or maybe I didn’t understand the problem.
@nilsnolde Thanks for your prompt reply. I think that's the issue.
I just found another related issue. Every time pyvalhalla returns the RuntimeError (listed below), if I run the map matching request again, it will induce a kernel restarting window saying The kernel for this ipynd appears to have died. It will restart automatically. I am working in a Jupyter Lab environment. Do you know why did this occur?
RuntimeError: Map Match algorithm failed to find path:map_snap algorithm failed to snap the shape points to the correct shape.
Sorry, no idea. I'd guess in a simple Python environment it works right? I have no clue what weirdness a Jupyter Lab environment introduces, it should just be a sorta normal Python RuntimeError
that's emitted (even if it's originating in C++). Can you share the relevant code snippet?
I have tried in the simple Python environment but it did not work. The same issue occurred. Error handling helps skipped the current loop when the map matching failed but the next round of map matching caused the program to stop. I listed the codes below.
for trip in trips:
## create query
coords = trip[['lat', 'lon', 'new_time']].to_json(orient='records')
query_head = '{"shape":'
query_tail = ""","search_radius": 50, "shape_match":"map_snap", "costing":"auto", "format":"osrm"}"""
query_body = query_head + coords + query_tail
try:
## map matching
response = json.loads(actor.trace_attributes(query_body))
except RuntimeError:
continue
would've expected that to work.. I'll look into it in a few weeks when I have more time.
Thank you. I have tested the same process by using the Valhalla docker image. It worked well.
I quickly tried reproducing this on a Berlin dataset, but it works fine for me:
from valhalla import Actor, get_config
coords = [
[[16.689606,48.211862],[16.362762,48.210947]], # Vienna, will throw RuntimeError
[[13.352509,52.488634],[13.533783,52.552141]] # Berlin
]
conf = get_config('/home/nilsnolde/dev/cpp/valhalla/site/berlin_tiles_traffic.tar')
actor = Actor(conf)
for coord_pair in coords:
req = {"locations": [{"lon": coord_pair[0][0], "lat": coord_pair[0][1]}, {"lon": coord_pair[1][0], "lat": coord_pair[1][1]}], "costing": "auto"}
try:
res = actor.route(req)
except RuntimeError as e:
print(e)
continue
print(res['trip']['status_message'])
First it fails and then finds the second route without a problem. If I just replace route
with trace_attributes
it fails both times, but the interpreter never gets hung up.
I did this in ipython with Python 3.10 on Arch Linux. What were you using?
I was using Python 3.10.6 on Windows 10. My pyvalhalla version is 3.0.3.
Hmpf that really sucks.. we don’t use these bindings yet intensely cross platform but have plans to do so. Anyways, thanks for the report, I’ll mentally prepare for a disgusting dev experience😣
Anyway, the docker Valhalla works well for me. I will try Linux someday in the future.
Thank you again. You guys really do a great job! This package helps a lot in my project.
Let’s keep this open, it’ll remind me of this issue
I tested on a Linux machine today and the map matching still did not work (return "Segmentation fault") after a RuntimeError happened. Not all RuntimeError caused this issue. For example, if the RuntimeError return "reaching the maximum number of points", then it did not cause this issue. The issue only happened when the RuntimeError returned "Exact route match algorithm failed to find path".
Segfault is much more serious and definitely is a Valhalla issue. Can you isolate that request somehow? That’d be valuable.
Hi,
I am map matching a large number of trips to the roads (more than 1000). I currently use a for-loop strategy to match one trip for each request. The issue is when there is a failed match, pyvalhalla will return an error message and stop the loop. Is there a configuration to avoid pyvalhalla to return the error message?
Or is there a better way than for loop to map match a large number of trips?
Thank you so much.