jmsigner / amt

37 stars 13 forks source link

Issue with a-LoCoH polygons #66

Closed ronanhart closed 2 years ago

ronanhart commented 2 years ago

Hello,

I am trying to delineate UDs using a-LoCoH with 10 isopleths ranging from 15%-95%. To calculate the number of neighbors, I am using the max distance between points (per individual). I first delineated these months ago (Dec 2021) and they seem fine (picture 1). I have to re-do these delineations, however, because of some new and cleaned GPS data. I didn't change my code at all except to input the new data, but the UD hulls look very different (see picture 2). I'm currently using amt version 0.1.7, but I'm not sure what version I was using in Dec 2021 (I don't know if I had updated to whatever the most recent version was at that time).

For both pictures I filtered only the 95% isopleth: 1 picture 1 2 picture 2

Do you know what could be happening here and how to fix it? Thank you very much,

Ronan

Edit: I forgot to add a reproducible example

library(amt)
library(tidyverse)
library(sf)

data(deer)

max_dist <- deer %>%
  select(x_, y_) %>%
  dist() %>%
  max()

locoh <- deer %>%
  hr_locoh(levels = seq(0.15, 0.95, length.out = 10),
           keep.data = TRUE,
           n = max_dist,
           type = "a",
           rand_buffer = 1e-05)

locoh$locoh %>%
  filter(level == max(level)) %>%
  ggplot() +
  geom_sf(aes(fill = level))
bsmity13 commented 2 years ago

To my eye, this looks like an issue merging polygons. @jmsigner, does this look like that to you?

I just ran the example above with amt v 0.1.4 (archived 2021-01-18) and amt v 0.1.7 and got identical results.

bsmity13 commented 2 years ago

Turns out that I can fix this problem (using the dataset that @ronanhart used to make images above) by reverting to amt v0.1.4. The issue arises because of using sf::st_union() in place of rgeos::gBuffer().

JoshOBrien commented 2 years ago

As noted here, the problem apparently traces to a regression in sf.

JoshOBrien commented 2 years ago

I believe I've fixed this issue with PR https://github.com/jmsigner/amt/pull/68.