Limit number of points returned by direction

I’m using the Python SDK, mainly the directions feature of ORS. I am wondering if I can limit how many points the API returns.
Right now, I am getting over 2400 waypoints, and I would prefer around 200. I could randomly downsample, but I know that some points are closer to each other, so the logic would be cumbersome if I did it any way other than randomly.

I’m hoping there is a built-in way to do this. I read through the source code and don’t believe I saw anything.

I made a pretty simple workaround with Ramer-Douglas-Peucker: Ramer-Douglas-Peucker Algorithm — Ramer-Douglas-Peucker Algorithm (rdp) 0.7 documentation

Still interested in other options.


I’m a bit unsure what you’re trying to achive here.
The ors will return all waypoints necessary to define the geometry of your route correctly¹.
Removing waypoints from your route will make the route incorrect.
For a high-level overview, this might indeed be preferable, as we might not need all points of a highway entry when looking at it from a distance.
Simplifications like these are not done by the ors, since it can’t know what you want to do with your data and we try to keep resource usage to a minimum.

If you want to do it yourself, line simplification algorithms like the mentioned Douglas-Peucker are the way to go.
For this, maybe have a look at the Visvalingam algorithm or any of the others mentioned there.

Best regards

[1]: Yes, some points, especially in urban areas, might seem superflous, but they are necessary for correctness and for the vast majority of points returned, the statement holds.

1 Like

Also see this thread: