Closed JoshOBrien closed 2 years ago
In case it helps, here are images of the home ranges produced by the following code, first using the version of amt currently on CRAN, amt-0.1.7
, then the version in this PR. (In both cases, I used sf-1.0.7
, the version of sf currently on CRAN.)
library(sf)
library(amt)
library(tidyverse)
data(deer)
max_dist <- deer %>%
select(x_, y_) %>%
dist() %>%
max()
locoh <- deer %>%
hr_locoh(levels = 0.95,
keep.data = TRUE,
n = max_dist,
type = "a",
rand_buffer = 1e-05)
locoh$locoh %>%
filter(level == max(level)) %>%
ggplot() +
geom_sf(aes(fill = level))
@JoshOBrien Thanks for fixing this and taking are of it!
@jmsigner You bet. Thanks right back at you for all your work on this package.
This commit fixes the problems with
hr_locoh()
caused by recent changes to the sf package (discussed in #66)With this commit, (as part of its move away from any reliance on the rgeos package) the sf package modified the code it uses to implement
sf:::st_as_sfc.SpatialPolygons()
. One consequence of this change is thatst_as_sfc()
now handlesSpatialPolygons
containing several overlapping polygons differently than it did before. Previously it converted them faithfully to ansfc
MULTIPOLYGON
. Now (while executing these two lines of code) it often splits overlapping polygons up into multiple smaller polygons. (It's the call tost_make_valid()
in particular that alters the component polygons, following rules I can guess at but haven't fully unpacked.)In any case, we can sidestep this issue in amt by the simple step of giving each of the polygons that make up
ff
(which is passed tost_as_sf()
here inamt:::hr_locoh.track_xy()
) its own ID. By making that single change, this commit restoreshr_locoh()
's functionality in the half dozen cases in which I've tested it.