2

Given a route between a start point and an end point, how to find efficiently Points of Interest (POIs) (given by their long / lat coordinates) along this route, at a maximum distance D_max?

A naive approach would be to move a circle of radius D_max along this route, and look for POIs inside this circle; but if circles don't overlap we may forget POIs, and if they overlap, we will find same POI several times, so it is not efficient.

What would be a better approach?

(Note: I don't know if SO is the best place for this question, or if I should post it on CS, or Software Engineering, or elsewhere?)

2
  • 2
    So you need to find points at given distance (and closer) from polyline?
    – MBo
    Commented Sep 7, 2017 at 8:03
  • That's it. Good reformulation :)
    – Greg82
    Commented Sep 7, 2017 at 8:04

2 Answers 2

3

You need to find distance from polyline in lat/lon coordinates and given point and compare it with maximum distance.

It is possible to get cross-track distance (GI at the picture) from here for every route segment:

Formula:    dxt = asin( sin(δ13) ⋅ sin(θ13−θ12) ) ⋅ R
where    δ13 is (angular) distance from start point to third point
 θ13 is (initial) bearing from start point to third point
 θ12 is (initial) bearing from start point to end point
 R is the earth’s radius
JavaScript: var dXt = Math.asin(Math.sin(d13/R)*Math.sin(θ13-θ12)) * R;

as well as along-track distance (BI at the picture):

Formula:    dat = acos( cos(δ13) / cos(δxt) ) ⋅ R
where    δ13 is (angular) distance from start point to third point
 δxt is (angular) cross-track distance
 R is the earth’s radius
JavaScript: var dAt = Math.acos(Math.cos(d13/R)/Math.cos(dXt/R)) * R;

and compare along-track distance with start-end distance (if it is negative or larger, then the closest point is end of segment - BH case at the picture, here HC is the smallest distance ot BC segment)

enter image description here

Bearing and distance calculations are on the same page.

If you are using some geo libraries, they should contain functions for such task.

2
  • I want to use this formula to point is near the a path. Not clear to me how to formula works. Suppose user going B to C, and want to check G is near or far from BC path. Is there a way to get GI distance?
    – Janaka
    Commented Jul 19, 2021 at 17:14
  • @ Janaka Yes, my first citation shows the way. You also need angular distance and bearings - link contains corresponding formulas.
    – MBo
    Commented Jul 19, 2021 at 17:29
2

Assuming you have your POI points indexed in some space partitioning data structure as a k-d tree or a quadtree, implementing a find-points-near-polyline algorithm shouldn't be too difficult.

  1. From the polyline obtain the set of segments conforming it.
  2. Descend recursively into your space partitioning data strucure filtering at every level the set of segments by the distance to the space partition enclosing box.
  3. Once you reach a final node, use brute force to check the distance between the remaining vectors in the set at that point and the POI in the partition.

Not the answer you're looking for? Browse other questions tagged or ask your own question.