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

Bug: isoline fails when response polygon is multipart #121

Closed
hrecht opened this issue Apr 1, 2021 · 2 comments · Fixed by #126
Closed

Bug: isoline fails when response polygon is multipart #121

hrecht opened this issue Apr 1, 2021 · 2 comments · Fixed by #126
Assignees
Labels
bug Something isn't working

Comments

@hrecht
Copy link

hrecht commented Apr 1, 2021

Describe the bug
I'm running isoline() on many points and am getting the following errors on a small number. I've discovered that this is happening response returns multiple polygons, by using the url_only option to see the returned data in the browser. This might be happening because it's near a coastline and islands? Just a guess.

When using multiple times in range:
Error in UseMethod("decode_sf", encoded) : no applicable method for 'decode_sf' applied to an object of class "list"

When using just one time:
Error in decode(encoded[[x]]) : Invalid format version

Reproducible example

point_test <- data.frame(
	latitude = 41.73076,
	longitude = -72.79058)

point_test <- st_as_sf(point_test, coords = c("longitude", "latitude")) %>% 
	st_set_crs(4326)

test <- isoline(
	poi = point_test,
	range = 180 * 60,
	range_type = "time",
	transport_mode = "car",
	url_only = F,
	optimize = "quality",
	traffic = F,
	aggregate = F
)
test2 <- isoline(
	poi = point_test,
	range = c(120 * 60, 180 * 60),
	range_type = "time",
	transport_mode = "car",
	url_only = F,
	optimize = "quality",
	traffic = F,
	aggregate = F
)

Expected behavior
Successful isolines returned.

Optionally: R session info
version R version 4.0.4 (2021-02-15)
os macOS Catalina 10.15.7

@hrecht hrecht added the bug Something isn't working label Apr 1, 2021
@munterfi munterfi self-assigned this Apr 5, 2021
@munterfi
Copy link
Owner

munterfi commented Apr 7, 2021

Hi - thanks for reporting!

Indeed, multipart polygons were not considered at all in isoline(). With the development version of the package, it should now work as expected:

library(hereR)
library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.1

point_test <- data.frame(
    latitude = 41.73076,
    longitude = -72.79058)

point_test <- st_as_sf(point_test, coords = c("longitude", "latitude")) %>% 
    st_set_crs(4326)

(test <- isoline(
    poi = point_test,
    range = 180 * 60,
    range_type = "time",
    transport_mode = "car",
    url_only = F,
    optimize = "quality",
    traffic = F,
    aggregate = F
))
#> Simple feature collection with 1 feature and 5 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -75.62988 ymin: 40.16602 xmax: -70.09277 ymax: 44.0332
#> Geodetic CRS:  WGS 84
#>   id rank departure arrival range                       geometry
#> 1  1    1      <NA>    <NA> 10800 MULTIPOLYGON (((-75.58044 4...

(test2 <- isoline(
    poi = point_test,
    range = c(120 * 60, 180 * 60),
    range_type = "time",
    transport_mode = "car",
    url_only = F,
    optimize = "quality",
    traffic = F,
    aggregate = F
))
#> Simple feature collection with 2 features and 5 fields
#> Geometry type: GEOMETRY
#> Dimension:     XY
#> Bounding box:  xmin: -75.62988 ymin: 40.16602 xmax: -70.09277 ymax: 44.0332
#> Geodetic CRS:  WGS 84
#>   id rank departure arrival range                       geometry
#> 1  1    1      <NA>    <NA>  7200 POLYGON ((-74.52576 41.4404...
#> 2  1    2      <NA>    <NA> 10800 MULTIPOLYGON (((-75.58044 4...

And looks plausible:

library(mapview)
#> GDAL version >= 3.1.0 | setting mapviewOptions(fgb = TRUE)
mapviewOptions(fgb=FALSE)
mapview(
  test2[order(test2$rank, decreasing = TRUE), ],
  zcol = "range", layer.name = "iso"
)

iso

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.5 (2021-03-31)
#>  os       macOS Big Sur 10.16         
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       Europe/Zurich               
#>  date     2021-04-07                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package           * version    date       lib source        
#>  assertthat          0.2.1      2019-03-21 [1] CRAN (R 4.0.0)
#>  base64enc           0.1-3      2015-07-28 [1] CRAN (R 4.0.0)
#>  brew                1.0-6      2011-04-13 [1] CRAN (R 4.0.0)
#>  cachem              1.0.4      2021-02-13 [1] CRAN (R 4.0.2)
#>  callr               3.5.1      2020-10-13 [1] CRAN (R 4.0.2)
#>  class               7.3-18     2021-01-24 [1] CRAN (R 4.0.5)
#>  classInt            0.4-3      2020-04-07 [1] CRAN (R 4.0.0)
#>  cli                 2.3.1      2021-02-23 [1] CRAN (R 4.0.2)
#>  codetools           0.2-18     2020-11-04 [1] CRAN (R 4.0.5)
#>  colorspace          2.0-0      2020-11-11 [1] CRAN (R 4.0.2)
#>  crayon              1.4.1      2021-02-08 [1] CRAN (R 4.0.2)
#>  crosstalk           1.1.1      2021-01-12 [1] CRAN (R 4.0.2)
#>  curl                4.3        2019-12-02 [1] CRAN (R 4.0.1)
#>  data.table          1.14.0     2021-02-21 [1] CRAN (R 4.0.2)
#>  DBI                 1.1.1      2021-01-15 [1] CRAN (R 4.0.2)
#>  desc                1.2.0      2018-05-01 [1] CRAN (R 4.0.0)
#>  devtools            2.3.2      2020-09-18 [1] CRAN (R 4.0.2)
#>  digest              0.6.27     2020-10-24 [1] CRAN (R 4.0.2)
#>  dplyr               1.0.4      2021-02-02 [1] CRAN (R 4.0.2)
#>  e1071               1.7-4      2020-10-14 [1] CRAN (R 4.0.2)
#>  ellipsis            0.3.1      2020-05-15 [1] CRAN (R 4.0.0)
#>  evaluate            0.14       2019-05-28 [1] CRAN (R 4.0.0)
#>  fansi               0.4.2      2021-01-15 [1] CRAN (R 4.0.2)
#>  farver              2.0.3      2020-01-16 [1] CRAN (R 4.0.0)
#>  fastmap             1.1.0      2021-01-25 [1] CRAN (R 4.0.2)
#>  flexpolyline        0.2.1      2021-01-04 [1] CRAN (R 4.0.2)
#>  fs                  1.5.0      2020-07-31 [1] CRAN (R 4.0.2)
#>  generics            0.1.0      2020-10-31 [1] CRAN (R 4.0.2)
#>  glue                1.4.2      2020-08-27 [1] CRAN (R 4.0.2)
#>  hereR             * 0.6.1.9000 2021-04-07 [1] local         
#>  htmltools           0.5.1.1    2021-01-22 [1] CRAN (R 4.0.2)
#>  htmlwidgets         1.5.3      2020-12-10 [1] CRAN (R 4.0.2)
#>  jsonlite            1.7.2      2020-12-09 [1] CRAN (R 4.0.2)
#>  KernSmooth          2.23-18    2020-10-29 [1] CRAN (R 4.0.5)
#>  knitr               1.31       2021-01-27 [1] CRAN (R 4.0.2)
#>  lattice             0.20-41    2020-04-02 [1] CRAN (R 4.0.5)
#>  leafem              0.1.3      2020-07-26 [1] CRAN (R 4.0.2)
#>  leaflet             2.0.4.1    2021-01-07 [1] CRAN (R 4.0.2)
#>  leaflet.providers   1.9.0      2019-11-09 [1] CRAN (R 4.0.0)
#>  leafpop             0.0.6      2020-09-22 [1] CRAN (R 4.0.2)
#>  lifecycle           1.0.0      2021-02-15 [1] CRAN (R 4.0.2)
#>  magrittr            2.0.1      2020-11-17 [1] CRAN (R 4.0.2)
#>  mapview           * 2.9.0      2020-08-11 [1] CRAN (R 4.0.2)
#>  memoise             2.0.0      2021-01-26 [1] CRAN (R 4.0.2)
#>  munsell             0.5.0      2018-06-12 [1] CRAN (R 4.0.0)
#>  pillar              1.5.0      2021-02-22 [1] CRAN (R 4.0.2)
#>  pkgbuild            1.2.0      2020-12-15 [1] CRAN (R 4.0.2)
#>  pkgconfig           2.0.3      2019-09-22 [1] CRAN (R 4.0.0)
#>  pkgload             1.2.0      2021-02-23 [1] CRAN (R 4.0.2)
#>  png                 0.1-7      2013-12-03 [1] CRAN (R 4.0.0)
#>  prettyunits         1.1.1      2020-01-24 [1] CRAN (R 4.0.0)
#>  processx            3.4.5      2020-11-30 [1] CRAN (R 4.0.2)
#>  ps                  1.5.0      2020-12-05 [1] CRAN (R 4.0.2)
#>  purrr               0.3.4      2020-04-17 [1] CRAN (R 4.0.0)
#>  R6                  2.5.0      2020-10-28 [1] CRAN (R 4.0.2)
#>  raster              3.4-5      2020-11-14 [1] CRAN (R 4.0.2)
#>  Rcpp                1.0.6      2021-01-15 [1] CRAN (R 4.0.2)
#>  remotes             2.2.0      2020-07-21 [1] CRAN (R 4.0.2)
#>  rlang               0.4.10     2020-12-30 [1] CRAN (R 4.0.2)
#>  rmarkdown           2.7        2021-02-19 [1] CRAN (R 4.0.2)
#>  rprojroot           2.0.2      2020-11-15 [1] CRAN (R 4.0.2)
#>  satellite           1.0.2      2019-12-09 [1] CRAN (R 4.0.0)
#>  scales              1.1.1      2020-05-11 [1] CRAN (R 4.0.0)
#>  sessioninfo         1.1.1      2018-11-05 [1] CRAN (R 4.0.0)
#>  sf                * 0.9-8      2021-03-17 [1] CRAN (R 4.0.2)
#>  sp                  1.4-5      2021-01-10 [1] CRAN (R 4.0.2)
#>  stringi             1.5.3      2020-09-09 [1] CRAN (R 4.0.2)
#>  stringr             1.4.0      2019-02-10 [1] CRAN (R 4.0.2)
#>  svglite             2.0.0      2021-02-20 [1] CRAN (R 4.0.2)
#>  systemfonts         1.0.1      2021-02-09 [1] CRAN (R 4.0.2)
#>  testthat            3.0.2      2021-02-14 [1] CRAN (R 4.0.2)
#>  tibble              3.1.0      2021-02-25 [1] CRAN (R 4.0.2)
#>  tidyselect          1.1.0      2020-05-11 [1] CRAN (R 4.0.0)
#>  units               0.7-0      2021-02-25 [1] CRAN (R 4.0.2)
#>  usethis             2.0.1      2021-02-10 [1] CRAN (R 4.0.2)
#>  utf8                1.1.4      2018-05-24 [1] CRAN (R 4.0.0)
#>  uuid                0.1-4      2020-02-26 [1] CRAN (R 4.0.0)
#>  vctrs               0.3.6      2020-12-17 [1] CRAN (R 4.0.2)
#>  webshot             0.5.2      2019-11-22 [1] CRAN (R 4.0.0)
#>  withr               2.4.1      2021-01-26 [1] CRAN (R 4.0.2)
#>  xfun                0.21       2021-02-10 [1] CRAN (R 4.0.2)
#>  yaml                2.2.1      2020-02-01 [1] CRAN (R 4.0.0)
#> 
#> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

@hrecht
Copy link
Author

hrecht commented Apr 7, 2021

Wonderful, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants