Hacker News new | ask | show | jobs
by jfpuget 3839 days ago
Thank you for the suggestion.

At first glance, it does not seem to provide an object for dealing with a finite set of points. Using it would require first to transform the track into a continuous line, via interpolate(), then project() each waypoint to find the nearest point on that line. Issue is that this will not give me one of the original points of the track, which is what I needed.

But I may be wrong.

2 comments

I'm curious about why that was? From the graph showing the raam datapoints, there's a region with large gaps between points, and it would choose a track point that's well away from the original?

I've written some code to deal with this before (in my case, I wrote a distributed timer for cycle races, predicting current rider locations and gaps from sparse user reports). For me, finding nearest point on the segments of the polyline worked, but choosing only vertices would have made the time estimates terrible. Were the points somehow more fixed than that, eg towns/motels on the route?

The waypoints are not distributed regularly, but the track points are.

Here is why performance mattered in my case.

I needed to predict future positions of the cyclist (see https://www.ibm.com/developerworks/community/blogs/jfp/entry...). The computation relied mostly on weather forecasts provided for each track points.

I then needed to know where to start my computation, i.e. find the track point closest to the current location of the cyclist.

Good point. I'm not sure off the top of my head if Shapely has a specific function for what you're trying to do. It does have highly-optimized distance functions though. Might be interesting to compare those to your version.

One way I've approached this problem that seems pretty fast is to load a set of points into a PostGIS-enabled database, then use the `ST_Distance` function and order by distance.

[Edit]

Shapely solution:

    points = MultiPoint(((0, 0), (1, 1), (4, 4)))
    point = Point((3, 3))
    sorted(((p, p.distance(point)) for p in points), key=lambda item: item[1])