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

hr_to_sf returns object length mismatch error #84

Open
mainahandmaker opened this issue Jan 2, 2023 · 2 comments
Open

hr_to_sf returns object length mismatch error #84

mainahandmaker opened this issue Jan 2, 2023 · 2 comments

Comments

@mainahandmaker
Copy link

mainahandmaker commented Jan 2, 2023

I used the hr_kde function to calculate KDE daily home ranges for many individuals, and am now attempting to use the hr_to_sf() function to convert the list column with KDE home range estimates into sf objects for plotting and other sf operations. This used to work perfectly for me, but now is generating the following error:

Error in sp::SpatialPolygonsDataFrame(con, df) : Object length mismatch: con has 1 Polygons objects, but df has 2 rows

Any thoughts on what might be causing the hr_to_sf() function to return this error? Many thanks!

Session info below:

R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] furrr_0.3.1 future_1.30.0 tidyr_1.2.1 readr_2.1.3 purrr_0.3.5 mapview_2.11.0
[7] lubridate_1.9.0 timechange_0.1.1 dplyr_1.0.10 sf_1.0-9 ggmap_3.0.1 ggplot2_3.4.0
[13] amt_0.1.7

loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 lattice_0.20-45 listenv_0.9.0 png_0.1-8 class_7.3-20
[6] assertthat_0.2.1 digest_0.6.30 utf8_1.2.2 parallelly_1.33.0 R6_2.5.1
[11] plyr_1.8.8 backports_1.4.1 stats4_4.2.1 e1071_1.7-12 httr_1.4.4
[16] pillar_1.8.1 Rdpack_2.4 RgoogleMaps_1.4.5.3 rlang_1.0.6 rstudioapi_0.14
[21] raster_3.6-11 Matrix_1.4-1 checkmate_2.1.0 splines_4.2.1 webshot_0.5.4
[26] stringr_1.5.0 htmlwidgets_1.5.4 munsell_0.5.0 proxy_0.4-27 compiler_4.2.1
[31] pkgconfig_2.0.3 base64enc_0.1-3 rgeos_0.5-9 globals_0.16.2 htmltools_0.5.3
[36] tidyselect_1.2.0 tibble_3.1.8 codetools_0.2-18 fansi_1.0.3 tzdb_0.3.0
[41] withr_2.5.0 bitops_1.0-7 rbibutils_2.2.10 grid_4.2.1 satellite_1.0.4
[46] gtable_0.3.1 lifecycle_1.0.3 DBI_1.1.3 magrittr_2.0.3 units_0.8-0
[51] scales_1.2.1 KernSmooth_2.23-20 cli_3.4.1 stringi_1.7.8 leaflet_2.1.1
[56] sp_1.5-1 ellipsis_0.3.2 generics_0.1.3 vctrs_0.5.1 tools_4.2.1
[61] leafem_0.2.0 glue_1.6.2 hms_1.1.2 crosstalk_1.2.0 jpeg_0.1-10
[66] parallel_4.2.1 fastmap_1.1.0 survival_3.3-1 colorspace_2.0-3 terra_1.6-47
[71] classInt_0.4-8

@jmsigner
Copy link
Owner

The following works for me:

library(amt)
#> 
#> Attaching package: 'amt'
#> The following object is masked from 'package:stats':
#> 
#>     filter
data(deer)

deer |> mutate(month = lubridate::month(t_)) |> 
  nest(dat = -month) |> 
  mutate(hr = map(dat, hr_kde)) |> hr_to_sf(hr)
#> Warning in fun(libname, pkgname): rgeos: versions of GEOS runtime 3.10.1-CAPI-1.16.0
#> and GEOS at installation 3.9.1-CAPI-1.14.2differ
#> Simple feature collection with 7 features and 3 fields
#> Geometry type: GEOMETRY
#> Dimension:     XY
#> Bounding box:  xmin: 4308459 ymin: 3441894 xmax: 4320290 ymax: 3452486
#> Projected CRS: ETRS89 / LAEA Europe
#>   level     what           area                       geometry
#> 1  0.95 estimate  7587092 [m^2] POLYGON ((4311006 3445134, ...
#> 2  0.95 estimate 10331200 [m^2] POLYGON ((4310787 3446195, ...
#> 3  0.95 estimate 50075268 [m^2] POLYGON ((4309621 3446230, ...
#> 4  0.95 estimate 11790773 [m^2] POLYGON ((4313355 3449232, ...
#> 5  0.95 estimate  9816956 [m^2] POLYGON ((4313768 3449268, ...
#> 6  0.95 estimate  9768871 [m^2] MULTIPOLYGON (((4311317 344...
#> 7  0.95 estimate 23912372 [m^2] POLYGON ((4308498 3443105, ...

Created on 2023-01-13 by the reprex package (v2.0.1)

Could you send me a small subset of your data (by email is fine) that reproduces the problem?

@mainahandmaker
Copy link
Author

mainahandmaker commented Jan 13, 2023 via email

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