3
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ This is tricky. Note first that, for nonzero numbers, SetAccuracy[x, a] is equivalent to SetPrecision[x, a + Log10[Abs[x]]], so the result of SetAccuracy depends on the magnitude of $x$. In other words, you are setting a higher precision with SetAccuracy[..., 4] than you perhaps expected. $\endgroup$ – MarcoB Jul 6 '18 at 15:08
  • $\begingroup$ This is not related to GeoPosition. Removing GeoPosition /@ 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:14
  • $\begingroup$ Thanks for the input. Looking at the Wolfram website on numerical precision, I see that "The accuracy is the effective number of these digits which appear to the right of the decimal point." That is what I am trying to set. What confuses me is that SetPrecision and SetAccuracy are functioning like I would expect, but it isn't translating into the GeoPosition data. Consider the following: point = data[[1, 1, 1]] (*34.5817*) and SetAccuracy[point, 3](*34.58*), SetPrecision[point, 3](*34.58*). $\endgroup$ – kickert Jul 6 '18 at 15:23
  • $\begingroup$ Having learned a bit about accuracy and precision in Mathematica, I do see how they are different now even if the outputs are the same. (Using the outputs from above, I see both figures have different accuracies and precisions despite the output both being 34.58) So how can I effectively round all lats and longs to the nearest 4th decimal place. (This provides accuracy to around 10 meters, which is plenty, but some files I am working with have up to 10 decimal places.) $\endgroup$ – kickert Jul 6 '18 at 15:31
2
$\begingroup$

Having read the helpful comments about Accuracy and Precision in Mathematica, I see that what I really want to use is the Round Function.

ClearAll[data];
ToExpression@Import["https://pastebin.com/raw/8KDcvMex", "String"];
data = DeleteDuplicates[Round[data, 0.001]];
trail = GeoPosition /@ data[[All, 1]];
Length[trail]
(*907*)

Thanks for the help!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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