Skip to content

Commit

Permalink
Do not divide into half
Browse files Browse the repository at this point in the history
Close #31
  • Loading branch information
uribo committed May 15, 2019
1 parent 420e2a4 commit 596d705
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
17 changes: 2 additions & 15 deletions R/mesh_to_latlon.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,15 @@ mesh_to_coords <- function(meshcode, ...) {
}

if (exists("code9")) {

res$lat_error <- 0.004165
res$lng_error <- 0.00625

res <- finename_centroid(res, code9)
}
if (exists("code10")) {

res$lat_error <- res$lat_error / 2
res$lng_error <- res$lng_error / 2

res <- finename_centroid(res, code10)
}
if (exists("code11")) {

res$lat_error <- res$lat_error / 2
res$lng_error <- res$lng_error / 2

res <- finename_centroid(res, code11)
}

res <- tibble::as_tibble(res)

return(res)
tibble::as_tibble(res)

}
18 changes: 13 additions & 5 deletions tests/testthat/test-meshcode_to_latlon.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,20 @@ test_that(
"fine mesh", {
res <- mesh_to_coords(513377831)
expect_s3_class(res, "tbl_df")
expect_lte(res$lat_error, 0.3333)
expect_equal(res$lng_error, 0.00312, tolerance = 0.02)
expect_lte(res$lng_error, 0.5)

expect_equal(res$lat_error, 0.002083333, tolerance = 0.02)
expect_lte(res$lat_error, 0.3333)

res <- mesh_to_coords(5133778312)
expect_is(res$lat_error, "numeric")
expect_equal(res$lng_error, 0.00312 / 2, tolerance = 0.02)
expect_equal(res$lat_error, 0.002083333 / 2, tolerance = 0.02)

res <- mesh_to_coords(51337783123)
expect_is(res$lng_error, "numeric")
expect_equal(res$lng_error, 0.00312 / 4, tolerance = 0.02)
expect_equal(res$lat_error, 0.002083333 / 4, tolerance = 0.02)
}
)

Expand Down Expand Up @@ -98,12 +104,14 @@ test_that("fine mesh", {
expect_equal(
res$meshcode,
c("362337991", "362337992", "362337993", "362337994"))
expect_identical(
expect_equal(
res$lng_center,
c(123.990625, 123.996875, 123.990625, 123.996875))
c(123.990625, 123.996875, 123.990625, 123.996875),
tolerance = 0.002)
expect_equal(
res$lat_center,
c(24.32708, 24.32708, 24.33125, 24.33125), tolerance = 0.002)
c(24.32708, 24.32708, 24.33125, 24.33125),
tolerance = 0.002)
expect_equivalent(
res$lng_error[1], 0.003125)
})

0 comments on commit 596d705

Please sign in to comment.