hypertidy / geodist

Ultra lightweight, ultra fast calculation of geo distances
https://hypertidy.github.io/geodist/
Other
93 stars 7 forks source link

Fix cheapdist #6

Closed mpadge closed 6 years ago

mpadge commented 6 years ago

@mdsumner This one's for you, also to help you get your teeth into the code. I've implemented Haversine, Vincenty, and the mapbox cheap ruler, but the latter does not give consistent results:

n <- 50
dx <- dy <- 0.01
x <- cbind (-100 + dx * runif (n), 20 + dy * runif (n))
y <- cbind (-100 + dx * runif (2 * n), 20 + dy * runif (2 * n))
colnames (x) <- colnames (y) <- c ("x", "y")
d1 <- geodist (x, measure = "haversine")
d2 <- geodist (x, measure = "cheap")
plot (d1, d2, pch = 1)

junk

I think part of the problem is that the notes in their blog description purport to calculate cos((lat1 + lat2) / 2 as if these are in degrees rather than radians. I've converted them to radians, but have not converted other values. These kind of inconsistencies are the likely cause, and likely all that need be done is to look inside the cheap rule source code and fix my coded interpretation of the blog accordingly.

mdsumner commented 6 years ago

Looking awesome, just hit Thailand so will be a few weeks at least!

mpadge commented 6 years ago

oh cool - enjoy that break! there's no hurry on this, i just used it as a chance to up my R-C skillz! have fun, and let me know if you might have time anywhere in the vicinity