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

sf to sp problem in osrmIsochrones() #45

Closed
rCarto opened this issue May 15, 2019 · 6 comments
Closed

sf to sp problem in osrmIsochrones() #45

rCarto opened this issue May 15, 2019 · 6 comments

Comments

@rCarto
Copy link
Member

rCarto commented May 15, 2019

Hi there,

Thank you! This solved the error.

However, I ran into another problem with this set of coordinates, also in London:

test <- osrmIsochrone(loc = c(-2.4529553,52.71386), 
                           breaks = seq(from = 0,to=8,by=8))

For this, the error is:

Error in .as_Spatial(from, cast, IDs) : 
  conversion from feature type sfc_GEOMETRY to sp is not supported

This same error occurs for other few sets of coordinates that I have too.

Not sure what this means. Would appreciate your help, thank you!!

Originally posted by @jiaweniscute in #44 (comment)

@rCarto
Copy link
Member Author

rCarto commented May 15, 2019

There is a small bug.
A quick workaround is to return an sf object

library(osrm)
library(sf)
test <- osrmIsochrone(loc = c(-2.4529553,52.71386), 
                      breaks = seq(from = 0,to=8,by=8), 
                      returnclass = "sf")
st_geometry(test) <- st_collection_extract(x = st_geometry(test), 
                                           type = "POLYGON")
test <- as(test, "Spatial")

@rCarto rCarto closed this as completed in 67be00a May 15, 2019
@rCarto
Copy link
Member Author

rCarto commented May 15, 2019

The bug is fixed in the dev version of the package:
remotes::install_github("rCarto/osrm")

@jiaweniscute
Copy link

Hi There!

The manual workaround works!

However, the update doesnt seem to fix the error in

test <- osrmIsochrone(loc = c(-2.4529553,52.71386), 
                      breaks = seq(from = 0,to=8,by=8)

Ran remotes::install_github("rCarto/osrm") to get the updates but received the same error on the same set of coordinates.

Error in .as_Spatial(from, cast, IDs) : 
  conversion from feature type sfc_GEOMETRY to sp is not supported

Not sure if I missed anything!

@rCarto
Copy link
Member Author

rCarto commented May 16, 2019

Mmmm, what is your sessionInfo() after loading sf and osrm?

@jiaweniscute
Copy link

Oops, I am not sure why but it suddenly works today.

Perhaps I needed to restart my R session.

Here is my sessionInfo() anyway! - Thank you so much for your quick response!

R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Mojave 10.14.4

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
 [1] sf_0.7-3        raster_2.8-19   sp_1.3-1        osrm_3.3.0.9000 htmltools_0.3.6 mapview_2.6.3  
 [7] plotly_4.9.0    gplots_3.0.1.1  lattice_0.20-38 reshape_0.8.8   leaflet_2.0.2   lubridate_1.7.4
[13] forcats_0.4.0   stringr_1.4.0   dplyr_0.8.0.1   purrr_0.3.2     readr_1.3.1     tidyr_0.8.3    
[19] tibble_2.1.1    ggplot2_3.1.1   tidyverse_1.2.1

loaded via a namespace (and not attached):
 [1] httr_1.4.0         jsonlite_1.6       viridisLite_0.3.0  modelr_0.1.4       gtools_3.8.1      
 [6] shiny_1.3.2        assertthat_0.2.1   stats4_3.5.2       cellranger_1.1.0   yaml_2.2.0        
[11] pillar_1.3.1       backports_1.1.4    glue_1.3.1         digest_0.6.18      promises_1.0.1    
[16] rvest_0.3.3        colorspace_1.4-1   httpuv_1.5.1       plyr_1.8.4         pkgconfig_2.0.2   
[21] broom_0.5.2        haven_2.1.0        xtable_1.8-4       webshot_0.5.1      scales_1.0.0      
[26] gdata_2.18.0       satellite_1.0.1    later_0.8.0        generics_0.0.2     withr_2.1.2       
[31] lazyeval_0.2.2     cli_1.1.0          magrittr_1.5       crayon_1.3.4       readxl_1.3.1      
[36] mime_0.6           nlme_3.1-139       lwgeom_0.1-6       xml2_1.2.0         class_7.3-15      
[41] tools_3.5.2        data.table_1.12.2  hms_0.4.2          munsell_0.5.0      isoband_0.2.0     
[46] compiler_3.5.2     e1071_1.7-1        caTools_1.17.1.2   rlang_0.3.4        RCurl_1.95-4.12   
[51] units_0.6-2        classInt_0.3-1     grid_3.5.2         rstudioapi_0.10    htmlwidgets_1.3   
[56] crosstalk_1.0.0    labeling_0.3       bitops_1.0-6       base64enc_0.1-3    gtable_0.3.0      
[61] codetools_0.2-16   DBI_1.0.0          R6_2.4.0           rgdal_1.4-3        knitr_1.22        
[66] KernSmooth_2.23-15 stringi_1.4.3      Rcpp_1.0.1         png_0.1-7          tidyselect_0.2.5  
[71] xfun_0.6    

@rCarto
Copy link
Member Author

rCarto commented May 16, 2019

Glad it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants