I am continuing to work with GPS data related to trail routes and am trying to optimize the code by removing route points from a GPX file that are very close to each other by setting the accuracy of the data coming in. I have found a weird quirk where SetPrecision
results in duplicates that can be removed, but SetAccuracy
does not.
This code brings in the data, plots the trail, removes duplicates, reveals how many route points there are, and the allows you to see how many decimal places the route points have been calculated to:
ClearAll[data];
ToExpression@Import["https://pastebin.com/raw/8KDcvMex", "String"];
trail = DeleteDuplicates[GeoPosition /@ data[[All, 1]]];
Length[trail]
trail[[1]]
(*2031, 4 decimal places*)
[Note: There are 2128 points in the original dataset]
If I set the accuracy to drop it to 3 decimal places, you can see it reflects in the GeoPosition
but also returns the same number of points.
trailacc4 =
DeleteDuplicates[SetAccuracy[GeoPosition /@ data[[All, 1]], 4]];
Length[trailacc4]
trailacc4[[1]]
(*2031, 3 decimal places*)
Now, if I use SetPrecision
instead of SetAccuracy
I can get the same result in terms of decimal places, but it actually removes duplicates.
trailpre5 =
DeleteDuplicates[SetPrecision[GeoPosition /@ data[[All, 1]], 5]];
Length[trailpre5]
trailpre5[[1]]
(*746, 3 decimal places*)
With SetPrecision
every adjustment I make to the level of precision increases the number of duplicates as one would expect (precision of 4 gives two decimal places and 114 remaining route points). However, no matter what level of accuracy I set with SetAccuracy
I get the same result -- 2031 remaining route points. The GeoPosition
shows with fewer decimal points, but nothing is being removed.
Is this a bug, or do SetAccuracy
and SetPrecision
somehow work fundamentally differently with GeoPosition
?
With GPS data the difference between Accuracy and Precision makes a difference because you can have either 1, 2, or 3 figures to the left of the decimal.
I have tried setting the accuracy and precision directly to the data before GeoPositioning it, but every combination return 2037 resulting route points.
Thoughts?
SetAccuracy[x, a]
is equivalent toSetPrecision[x, a + Log10[Abs[x]]]
, so the result ofSetAccuracy
depends on the magnitude of $x$. In other words, you are setting a higher precision withSetAccuracy[..., 4]
than you perhaps expected. $\endgroup$ – MarcoB Jul 6 '18 at 15:08GeoPosition /@
from your inputs produces the same results. This is related to the different ways Precision and Accuracy work. I'd recommend to explore a simplified case, like the list of latitudes{34.5814, 34.5812, 34.5811, 34.5808, 34.5806, 34.5812, 34.5808}
. Note also that DeleteDuplicates uses SameQ by default. Use Equal as second argument for added tolerance. $\endgroup$ – jose Jul 6 '18 at 15:14SetPrecision
andSetAccuracy
are functioning like I would expect, but it isn't translating into theGeoPosition
data. Consider the following:point = data[[1, 1, 1]] (*34.5817*)
andSetAccuracy[point, 3](*34.58*)
,SetPrecision[point, 3](*34.58*)
. $\endgroup$ – kickert Jul 6 '18 at 15:23