valhalla / valhalla/valhalla

Is it possible to use polyline6 as input to matrix API, and if so, how?

Open
#5,435 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
6.2k
Forks
981
Avg merge
2d 14h
Merged PRs (30d)
14

Description

I was trying to update code I use for both OSRM and Valhalla, and I noticed that my Valhalla all-to-all function does not use polyline encoding of the input.

According to this page in the OSRM docs: https://project-osrm.org/docs/v5.24.0/api/#general-options, one can specify the coordinates of a table query using polyline6.

There are lots of vague words in the Valhalla docs that imply that one can do the same thing here, but nothing concrete.

So I just tried it and it doesn't seem to work, although in the past I've been tripped up by issues with polyline encoding and JSON.

Anyway, my attempt looks like this:

```
sources_to_targets?json={"sources": "uk%7BviA%60%7DeadF%7B%7CiDfel%40%60tdL~hRyaxI_grEyaAhyKhxpItx~Eo%7BuGqisA", "targets": "uk%7BviA%60%7DeadF%7B%7CiDfel%40%60tdL~hRyaxI_grEyaAhyKhxpItx~Eo%7BuGqisA", "costing": "auto", "shape_format": "polyline6"}
```

(If I swap out the polyline stuff with actual coordinate pairs the usual way, it works fine.)

I was hoping that using the "shape-format" parameter would just work.

My server responds with:
```
{"error_code":100,"error":"Failed to parse json request","status_code":400,"status":"Bad Request"}
```
And the log messages on the server say:
```
2025/08/08 19:45:36.941261 [INFO] Got Loki Request 69
2025/08/08 19:45:39.200910 [INFO] Got Thor Request 69
2025/08/08 19:45:39.201083 [INFO] matrix::costmatrix
69 2025/08/08 19:45:39.457319 200 10903
70 2025/08/08 20:22:39.147051 GET /sources_to_targets?json=%7B%22sources%22:%20%22svvyiAfrp%7CcFdoOy_a%40%60%60fIb%7DbG%7DxtKqyQf_s%40g_eEdkbCh%7BvEl__Aj%7B%60%40%22,%20%22targets%22:%20%22svvyiAfrp%7CcFdoOy_a%40%60%60fIb%7DbG%7DxtKqyQf_s%40g_eEdkbCh%7BvEl__Aj%7B%60%40%22,%20%22costing%22:%20%22auto%22,%20%22shape_format%22:%20%22polyline6%22%7D HTTP/1.1
2025/08/08 20:22:39.147409 [INFO] Got Loki Request 70
2025/08/08 20:22:39.147687 [WARN] 400::Insufficiently specified required parameter 'locations' or 'sources & targets' request_id=70
70 2025/08/08 20:22:39.147922 400 275
```

A good request with just plain lat, lon pairs gives this on the server:

```
73 2025/08/08 20:35:56.993322 GET /sources_to_targets?json=%7B%22sources%22:%20%5B%7B%22lat%22:%2039.077773,%20%22lon%22:%20-120.156923%7D,%20%7B%22lat%22:%2039.239968,%20%22lon%22:%20-120.052065%7D,%20%7B%22lat%22:%2039.234203,%20%22lon%22:%20-120.016998%7D,%20%7B%22lat%22:%2039.276152,%20%22lon%22:%20-120.121543%7D,%20%7B%22lat%22:%2039.244327,%20%22lon%22:%20-120.050522%7D,%20%7B%22lat%22:%2039.22675,%20%22lon%22:%20-120.08242%7D,%20%7B%22lat%22:%2039.240383,%20%22lon%22:%20-120.028053%7D%5D,%20%22targets%22:%20%5B%7B%22lat%22:%2039.077773,%20%22lon%22:%20-120.156923%7D,%20%7B%22lat%22:%2039.239968,%20%22lon%22:%20-120.052065%7D,%20%7B%22lat%22:%2039.234203,%20%22lon%22:%20-120.016998%7D,%20%7B%22lat%22:%2039.276152,%20%22lon%22:%20-120.121543%7D,%20%7B%22lat%22:%2039.244327,%20%22lon%22:%20-120.050522%7D,%20%7B%22lat%22:%2039.22675,%20%22lon%22:%20-120.08242%7D,%20%7B%22lat%22:%2039.240383,%20%22lon%22:%20-120.028053%7D%5D,%20%22costing%22:%20%22auto%22%7D HTTP/1.1
2025/08/08 20:35:56.993647 [INFO] Got Loki Request 73
2025/08/08 20:35:57.857900 [INFO] Got Thor Request 73
2025/08/08 20:35:57.858124 [INFO] matrix::costmatrix
73 2025/08/08 20:35:58.022537 200 8970
```

so I know the server is working fine and I can query it fine, I just don't know how to query it with polyline encoded input.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.