Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequential geodist produces different results to paired #19

Closed
mem48 opened this issue Apr 11, 2019 · 4 comments
Closed

Sequential geodist produces different results to paired #19

mem48 opened this issue Apr 11, 2019 · 4 comments

Comments

@mem48
Copy link

mem48 commented Apr 11, 2019

There seem to be different results produced when geodist is used in sequential mode or manually pairing the results

# Make example lon/lat points
mat <- matrix(c(-0.193011, 52.15549,
                -0.197722, 52.15395,
                -0.199949, 52.15527,
                -0.199533, 52.15762,
                -0.193205, 52.15757,
                -0.174015, 52.17529)
                , ncol = 2, byrow = TRUE)
colnames(mat) <- c("lon","lat")

# Use sequential mode
dist1 <- geodist::geodist(mat, sequential = TRUE)

# Manually make to and from objects
from <- mat[1:5,]
to <- mat[2:6,]
dist2 <- geodist::geodist(from, to, paired = TRUE)
identical(dist1, dist2) # FALSE
@mpadge
Copy link
Member

mpadge commented Apr 11, 2019

Oh yeah, you are indeed right there. Seems like a pretty mission-critical bug I've buried in there ...

@mem48
Copy link
Author

mem48 commented Apr 11, 2019

It has been causing me a headache all afternoon.

@mpadge
Copy link
Member

mpadge commented Apr 11, 2019

Even more interesting:

dist3 <- geodist::geodist(mat)
dist3 <- dist3 [which (row (dist3) == (col (dist3) + 1))] # off-diagonal
identical (dist3, dist1) # FALSE
identical (dist3, dist2) # TRUE

it's actually a bug in the sequential method!

@mpadge
Copy link
Member

mpadge commented Apr 11, 2019

library(geodist)
mat <- matrix(c(-0.193011, 52.15549,
                -0.197722, 52.15395,
                -0.199949, 52.15527,
                -0.199533, 52.15762,
                -0.193205, 52.15757,
                -0.174015, 52.17529),
              ncol = 2, byrow = TRUE)
colnames(mat) <- c("lon","lat")
from <- mat[1:5,]
to <- mat[2:6,]

measures <- c ("haversine", "vincenty", "cheap", "geodesic")
res <- sapply (measures, function (m) {
    dist1 <- geodist::geodist(mat, sequential = TRUE, measure = m)
    dist2 <- geodist::geodist(from, to, paired = TRUE, measure = m)
    dist3 <- geodist::geodist(mat, measure = m)
    dist3 <- dist3 [which (row (dist3) == (col (dist3) + 1))] # off-diagonal
    c (identical(dist1, dist2), identical(dist1, dist3), identical(dist2, dist3))
              })
rownames (res) <- c ("seq-paired", "seq-default", "paired-default")
knitr::kable (res)
haversine vincenty cheap geodesic
seq-paired TRUE TRUE FALSE TRUE
seq-default TRUE TRUE FALSE TRUE
paired-default TRUE TRUE TRUE TRUE

Created on 2019-04-11 by the reprex package (v0.2.1)

It's just a bug with sequential calculation using cheap distances ... now to find what must be an easy fix ...

@mpadge mpadge closed this as completed in c24b839 Apr 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants