Filter the coordinates generated from Directions API to 100 maximum

Hi!

I know - from this topic that I can extract an array of coordinates from the waypoints returned by Openrouteservice Api.

Now the question: I would to pass this array of coordinates to the MapBox Match Api so it can generates a route for the MapBox Navigator SDK based on the Openrouteservice route.

Unfortunately, MapBox Match Api gets a maximum of 100 coordinates as input, while Openrouteservice Api directions typically generates 200-300 of those coordinates.

Is there an algorithm or a method to reduce these coordinates to 100 consinstently?

Thanks in advance!

Hey,

I don’t think you can reduce the coordinates you get, since they might all be relevant.
Note, however, that they are already on existing roads, as that is what the ors returns.
Therefore, there is no need to Map Match them to existing roads.
If you still want to do that, though, I’d suggest splitting up your coordinates into batches of 100 and use the MapBox Match API sequentially.

Best regards

Thanks for your answee @jschnell !

I know that coordinates are already on existing roads. Point is that I want that MapBox Navigator get the exact route generated by Openrouteservice with the profile “byke-mountain” (that doesn’t exist in MapBox Api directions).

You could use line simplification on the output to produce similar lines with less points.
It might not work with the matching afterwards though, if the shape will be a lot different than before.

Best regards

Very interesting! Are there any examples of line simplification algorithms to a set of coordinates to draw routes on Osm?

Hey,

the link provided above contains code examples to both line simplification algorithms.
I’m sure more examples can be found in the depths of the web, albeit not in this forum, since this is a support forum for the openrouteservice.

Best regards

Openlayers has a simplify method on its Geometry object. AFAIK there’s no examples.
https://openlayers.org/en/latest/apidoc/module-ol_geom_Geometry-Geometry.html#simplify

1 Like