0

I'm looking for a good algorithm for finding a list nearest positions taking into account quality of data we receiving from gps devices.

The problem is as follows:

  1. I have a position of point A. A= (LNG, LAT, ALT, HorizontalAccuracy, VerticalAccuracy)
    • HorizontalAccuracy and VerticalAccuracy it's a potencial error in meters
  2. I have a list of others B = [B1, ... Bn] each Bx is (LNG, LAT, ALT, HorizontalAccuracy, VerticalAccuracy)
  3. I would like to find the list of points Bx nearest to A and order that list according to distance Bx and A.
  4. The order of that list should taken into account accuracy of data we have. The problem with accuracy starts when the distance between points is shorter then accuracy.
Luman75
  • 878
  • 1
  • 11
  • 28

3 Answers3

1

Simply use the Euclidean distance:

distance = sqrt((lng_a - lng_b)^2 + ... + (alt_a - alt_b)^2)

And then only sort by distance.

Jean Logeart
  • 52,687
  • 11
  • 83
  • 118
  • Sure that's the easier part, but what about errors of precision. I need to have them taken into account for proper handling relatively near objects – Luman75 Aug 22 '13 at 08:28
  • Please don't use Eucledian distance formula to calculate distance between to points on a sphere. – Rok Jarc Aug 22 '13 at 08:41
1

Precision: you can set a filter (ie: decide which locations you will use and which ones you will omit). In CLLocation you still get the centerpoint so there's not much of use for precision factor in a distance formula.

If you try to calculate distance between two geolocations with accuracy worse than their calculated distance between their centers that would be more of an approach problem than a mathematical problem.

Distance: you can always use CLLocation's distanceFromLocation: method. Don't use Eucledian formala to calculate distance between geolocations.

Sorting: not much to say here. Sorting algorithms have their pros and cons. I would first try to implement one of the native sorting possibilities and optimize later if they appear to be too slow.

Community
  • 1
  • 1
Rok Jarc
  • 18,765
  • 9
  • 69
  • 124
1

First the horicontal accuracy is only an estimate, so don#t rely to much on it. However I would remove the locations that exceed a accuracy threshold.

Then if you have less than 10.000 points sort by distance.
If you have more, then use a spatial index first, like Quadtree, to speed up by avoiding to calculate the distance to all locations, but only the one nearby.

Distance calculations:
That depends if your location sare spread over the wolrd, or only within 100km. If over the world, use the built in distanceTo(), if within 100km and you have many points or need a fast calculation, the use the distance formula based on equiRectangular projection, which uses only one cos() operation. The sqrt() you can ommit, since you probably can sort by sqr of the distance to.

AlexWien
  • 28,470
  • 6
  • 53
  • 83