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

Map matching: matched_points are missing in trace_attributes pbf response (different set of properties in pbf and json) #4708

Open
NorekZ opened this issue Apr 25, 2024 · 2 comments

Comments

@NorekZ
Copy link
Contributor

NorekZ commented Apr 25, 2024

Hello there,

I am struggling with a issue coming from the fact, that Valhalla json and pbf trace_attributes responses have very different model.

My scenario is the following: I need to compute average speed for all edges returned by trace_attributes based on my input points (coordinate+timestamp). So for each segment between two input points I need to break down the route to the corresponding (matched) edges. Additionally, I need to consider edge costs when breaking down.

At first, I went the PBF route because of convenience. It gave me edge costs (not seconds):

{
    "trip": {
        "routes": [
            {
                "legs": [
                    {
                        .....
                        "node": [
                            {
                                ......
                                "cost": {
                                    "elapsedCost": {
                                        "seconds": 13,
                                        "cost": 5.293943881988525
                                    },
                                    "transitionCost": {
                                        "seconds": 2.2084739208221436,
                                        "cost": 8
                                    }
                                }
                            }
                    }
                ]
            }
        ]
    }
}

Unfortunatelly, the second part I need for the computation (matched_points) is missing in PBF.

I realized that in JSON response, there are matched_points, but edge costs are missing.

Would be possible to include matched_points in the PBF response?

Shouldn't be those response formats more consistent/similar to each other? It's just format...

Thank you guys for all the work. It's a great project!

Norek

@nilsnolde
Copy link
Member

we use pbf for interprocess communication between the various valhalla modules and we actually just convert JSON from the pbf which we already have anyways. however, some stuff never made it into pbf and seems you hit one of the major ones. actually map matching doesn't even have its own pbf section, we re-use the routing stuff here too and add the matched_points (+ some other things e.g. the confidences scores) to the JSON based on the meili results.

I think by and large we're fairly consistent with pbf & json, but yeah, some things are lacking and need to be amended. for your particular case would it be enough to have the elapsed_cost in the JSON response? that'd be super quick to add, just add a writer("elapsed_cost", node.cost().elapsed_cost().cost()); here: https://github.com/valhalla/valhalla/blob/master/src/tyr/trace_serializer.cc#L307-L311

however, translating the meili results to pbf is a bit bigger..

@NorekZ
Copy link
Contributor Author

NorekZ commented Apr 26, 2024

Thank you for the quick response.

I made the suggested change is the linked PR.

Although it's much less convenient for me, at least it enables my whole use case.

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

No branches or pull requests

2 participants