Skip to content

Commit

Permalink
Merge pull request #49 from ropensci/fix/units-group-polys-area
Browse files Browse the repository at this point in the history
Fix/units group polys area
  • Loading branch information
robitalec committed Mar 13, 2023
2 parents 2749884 + ac637ec commit 3906e33
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
6 changes: 4 additions & 2 deletions R/build_polys.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,12 @@ build_polys <- function(DT = NULL,
}
} else if (hrType == 'kernel') {
kernelParam <- formals(adehabitatHR::kernelUD)
verticesParam <- formals(adehabitatHR::getverticeshr)
verticesParam <- formals(adehabitatHR::getverticeshr.estUD)

if (all(names(hrParams) %in% c(names(kernelParam), names(verticesParam)))) {

if (!('unout' %in% names(hrParams))) {
hrParams$unout <- 'm2'
}
kern <- do.call(adehabitatHR::kernelUD,
hrParams[intersect(names(hrParams), names(kernelParam))])
return(do.call(adehabitatHR::getverticeshr,
Expand Down
41 changes: 41 additions & 0 deletions tests/testthat/test-group-polys.R
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,44 @@ test_that('splitBy argument doesnt use splitBy column', {
)

})


test_that('group_polys with area returns proportions within 0-1', {

copyDT <- copy(DT)

utm <- 'EPSG:32736'

out_mcp <- suppressWarnings(group_polys(
DT = copyDT,
projection = utm,
hrType = 'mcp',
hrParams = list(percent = 95),
area = TRUE,
coords = c('X', 'Y'),
id = 'ID'
))

expect_true(all(
out_mcp$proportion >= 0 &
out_mcp$proportion <= 1.00001
)
)

out_kernel <- suppressWarnings(group_polys(
DT = copyDT,
projection = utm,
hrType = 'kernel',
hrParams = list(percent = 95),
area = TRUE,
coords = c('X', 'Y'),
id = 'ID'
))

expect_true(all(
out_kernel$proportion >= 0 &
out_kernel$proportion <= 1.00001
)
)

})

0 comments on commit 3906e33

Please sign in to comment.