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

line2points #418

Closed
G-dT opened this issue Jul 26, 2020 · 21 comments
Closed

line2points #418

G-dT opened this issue Jul 26, 2020 · 21 comments
Assignees

Comments

@G-dT
Copy link

G-dT commented Jul 26, 2020

Following from r-spatial/sf#761; attempting the example given there; with line2points (as per the latest stplanr doc) instead of line_to_points; the end point contains two 'y' values rather than an x and a y value.

I am using stplanr version: 0.6.2

A warning error is generated when running line2points which may be relevant:

Warning message:
In y_coords[d_indices] <- sapply(l_geometry, tail, n = 1) :
number of items to replace is not a multiple of replacement length

Abbreviated example:

library(sf)
library(stplanr)

l1 = routes_fast_sf[2, ]
p1 = line2points(l1)

Examining l1 shows:
bbox: xmin: -1.535849 ymin: 53.8282 xmax: -1.516748 ymax: 53.83041

However examining p1 shows:
bbox: xmin: -1.535849 ymin: -1.535849 xmax: -1.516748 ymax: 53.82868
geographic CRS: WGS 84
id geometry
1 1 POINT (-1.516748 53.82868)
2 1 POINT (-1.535849 -1.535849)

The same issue arises with the related example in the stplanr doc;

l <- routes_fast_sf[2:4, ]
lpoints <- line2points(l)

@Robinlovelace
Copy link
Member

Thanks for reporting but I cannot reproduce the bug.
Can you please show the full output of each of the lines of code shown below?

library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
library(stplanr)

l1 = routes_fast_sf[2, ]
p1 = line2points(l1)
b1 = sf::st_bbox(l1)
b2 = sf::st_bbox(p1)
identical(b1, b2)
#> [1] FALSE
b1
#>      xmin      ymin      xmax      ymax 
#> -1.535849 53.828200 -1.516748 53.830414
b2
#>      xmin      ymin      xmax      ymax 
#> -1.535849 53.828316 -1.516748 53.828682
plot(l1$geometry)
plot(p1$geometry, add = TRUE)

sessionInfo()
#> R version 3.6.3 (2020-02-29)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 18.04.4 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
#> 
#> locale:
#>  [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
#>  [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
#>  [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] stplanr_0.6.2 sf_0.9-5     
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.5           compiler_3.6.3       pillar_1.4.6        
#>  [4] highr_0.8            class_7.3-17         tools_3.6.3         
#>  [7] digest_0.6.25        evaluate_0.14        lifecycle_0.2.0.9000
#> [10] tibble_3.0.3         lattice_0.20-41      pkgconfig_2.0.3     
#> [13] rlang_0.4.7.9000     igraph_1.2.5         DBI_1.1.0           
#> [16] curl_4.3             yaml_2.2.1           xfun_0.15           
#> [19] e1071_1.7-3          raster_3.3-13        dplyr_1.0.0         
#> [22] stringr_1.4.0        knitr_1.29           rgeos_0.5-3         
#> [25] generics_0.0.2       vctrs_0.3.2          classInt_0.4-3      
#> [28] grid_3.6.3           tidyselect_1.1.0     glue_1.4.1          
#> [31] R6_2.4.1             foreign_0.8-76       rmarkdown_2.3       
#> [34] sp_1.4-2             purrr_0.3.4          magrittr_1.5        
#> [37] codetools_0.2-16     maptools_1.0-1       htmltools_0.5.0.9000
#> [40] ellipsis_0.3.1       units_0.6-7          geosphere_1.5-10    
#> [43] KernSmooth_2.23-17   stringi_1.4.6        crayon_1.3.4

Created on 2020-07-27 by the reprex package (v0.3.0)

@Robinlovelace Robinlovelace self-assigned this Jul 27, 2020
@G-dT
Copy link
Author

G-dT commented Jul 27, 2020

Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
> #> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
> library(stplanr)
> l1 = routes_fast_sf[2, ]
> p1 = line2points(l1)
Warning message:
In y_coords[d_indices] <- sapply(l_geometry, tail, n = 1) :
  number of items to replace is not a multiple of replacement length
> b1 = sf::st_bbox(l1)
> b2 = sf::st_bbox(p1)
> identical(b1, b2)
[1] FALSE
> #> [1] FALSE
> b1
     xmin      ymin      xmax      ymax 
-1.535849 53.828200 -1.516748 53.830414 
> #>      xmin      ymin      xmax      ymax 
> #> -1.535849 53.828200 -1.516748 53.830414
> b2
     xmin      ymin      xmax      ymax 
-1.535849 -1.535849 -1.516748 53.828682 
> #>      xmin      ymin      xmax      ymax 
> #> -1.535849 53.828316 -1.516748 53.828682
> plot(l1$geometry)
> plot(p1$geometry, add = TRUE)


> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252    LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                            LC_TIME=English_United Kingdom.1252    

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

other attached packages:
[1] stplanr_0.6.2 sf_0.9-5     

loaded via a namespace (and not attached):
 [1] tinytex_0.24       tidyselect_1.1.0   xfun_0.15          remotes_2.1.1      purrr_0.3.4        lattice_0.20-41    mapview_2.7.8     
 [8] colorspace_1.4-1   vctrs_0.3.1        generics_0.0.2     htmltools_0.5.0    stats4_4.0.2       viridisLite_0.3.0  base64enc_0.1-3   
[15] rlang_0.4.6        e1071_1.7-3        pillar_1.4.6       foreign_0.8-80     glue_1.4.1         DBI_1.1.0          sp_1.4-2          
[22] lifecycle_0.2.0    rgeos_0.5-3        munsell_0.5.0      raster_3.3-7       htmlwidgets_1.5.1  codetools_0.2-16   maptools_1.0-1    
[29] crosstalk_1.1.0.1  curl_4.3           class_7.3-17       fansi_0.4.1        leafem_0.1.1       Rcpp_1.0.5         KernSmooth_2.23-17
[36] geosphere_1.5-10   scales_1.1.1       classInt_0.4-3     satellite_1.0.2    leaflet_2.0.3      webshot_0.5.2      png_0.1-7         
[43] digest_0.6.25      dplyr_1.0.0        grid_4.0.2         cli_2.0.2          tools_4.0.2        magrittr_1.5       tibble_3.0.3      
[50] crayon_1.3.4       pkgconfig_2.0.3    ellipsis_0.3.1     assertthat_0.2.1   rstudioapi_0.11    R6_2.4.1           units_0.6-7       
[57] igraph_1.2.5       compiler_4.0.2 

@G-dT
Copy link
Author

G-dT commented Jul 27, 2020

And the image;
image

@G-dT
Copy link
Author

G-dT commented Jul 27, 2020

When I hover over the geometry column while viewing l1; it seems a strange line-break may be present in the data? (Clutching at straws, possibly).

image

@Robinlovelace
Copy link
Member

Thanks for the updated reprex @G-dT. I think it may be due to the combination of the PROJ version you have installed and the CRS of the packaged data...

@Robinlovelace
Copy link
Member

Could you try running these lines?:

lwgeom::st_startpoint(stplanr::routes_fast_sf[2, ])
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
#> Geometry set for 1 feature 
#> geometry type:  POINT
#> dimension:      XY
#> bbox:           xmin: -1.516748 ymin: 53.82868 xmax: -1.516748 ymax: 53.82868
#> geographic CRS: WGS 84
#> POINT (-1.516748 53.82868)

Created on 2020-07-27 by the reprex package (v0.3.0)

lwgeom::st_endpoint(stplanr::routes_fast_sf[2, ])
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
#> Geometry set for 1 feature 
#> geometry type:  POINT
#> dimension:      XY
#> bbox:           xmin: -1.535849 ymin: 53.82832 xmax: -1.535849 ymax: 53.82832
#> geographic CRS: WGS 84
#> POINT (-1.535849 53.82832)

Created on 2020-07-27 by the reprex package (v0.3.0)

@Robinlovelace
Copy link
Member

If you're still having issues I suggest setting the CRS of the object to NA. If that fails try updating the version of PROJ.

@G-dT
Copy link
Author

G-dT commented Jul 27, 2020

This works! Thank you

lwgeom::st_startpoint(stplanr::routes_fast_sf[2, ])
lwgeom::st_endpoint(stplanr::routes_fast_sf[2, ])

@Robinlovelace
Copy link
Member

Great. Is the issue fixed now from your perspective @G-dT ? Please close this issue if so. FYI I am working on a new package for OD data: https://github.com/ITSLeeds/od

Any comments on that or other stplanr issues are very welcome.

@Robinlovelace
Copy link
Member

Closing for now as I think it's an ephemeral issue affecting a specific and by now slightly out-of-date version of PROJ. If you have any further issues feel free to reopen @G-dT.

@G-dT
Copy link
Author

G-dT commented Jul 27, 2020

I've installed the latest PROJ via OSGeo4W but it is still v. 6.3.1 (latest stable windows release?) and problem persists. CRS of NA also doesn't fix the issue. Any further tips?

I can reproduce bug with my own dataset too.

line_bearing is also not working, suspect same base issue (presume line_bearing takes output from line2points and calls bearing from geosphere library?).

@Robinlovelace
Copy link
Member

Robinlovelace commented Jul 27, 2020

You could try converting the data to sp class. Or if you have Docker you could run a command like:

docker run -d -p 8783:8787 -v $(pwd):/home/rstudio/data -e PASSWORD=strongpass geocompr/geocompr

On that container I get:

library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
library(stplanr)
#> Warning in fun(libname, pkgname): rgeos: versions of GEOS runtime 3.8.0-CAPI-1.13.1
#> and GEOS at installation 3.6.2-CAPI-1.10.2differ

l1 = routes_fast_sf[2, ]
p1 = line2points(l1)
b1 = sf::st_bbox(l1)
b2 = sf::st_bbox(p1)
identical(b1, b2)
#> [1] FALSE
b1
#>      xmin      ymin      xmax      ymax 
#> -1.535849 53.828200 -1.516748 53.830414
b2
#>      xmin      ymin      xmax      ymax 
#> -1.535849 53.828316 -1.516748 53.828682
plot(l1$geometry)
plot(p1$geometry, add = TRUE)

sessionInfo()
#> R version 3.6.3 (2020-02-29)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 18.04.4 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] stplanr_0.5.2 sf_0.9-1     
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.4.6       compiler_3.6.3     pillar_1.4.3       highr_0.8         
#>  [5] class_7.3-16       tools_3.6.3        digest_0.6.25      lattice_0.20-41   
#>  [9] evaluate_0.14      tibble_3.0.0       lifecycle_0.2.0    pkgconfig_2.0.3   
#> [13] rlang_0.4.5        igraph_1.2.5       DBI_1.1.0          cli_2.0.2         
#> [17] curl_4.3           yaml_2.2.1         xfun_0.12          e1071_1.7-3       
#> [21] raster_3.0-12      dplyr_0.8.5        stringr_1.4.0      knitr_1.28        
#> [25] rgeos_0.5-2        vctrs_0.2.4        classInt_0.4-3     grid_3.6.3        
#> [29] tidyselect_1.0.0   glue_1.4.0         R6_2.4.1           fansi_0.4.1       
#> [33] foreign_0.8-76     rmarkdown_2.1      sp_1.4-1           purrr_0.3.3       
#> [37] magrittr_1.5       codetools_0.2-16   maptools_0.9-9     htmltools_0.4.0   
#> [41] ellipsis_0.3.0     units_0.6-6        assertthat_0.2.1   geosphere_1.5-10  
#> [45] KernSmooth_2.23-16 stringi_1.4.6      crayon_1.3.4

Created on 2020-07-27 by the reprex package (v0.3.0)

@Robinlovelace
Copy link
Member

Update: I can reproduce the issue in an image with an older version of PROJ:

library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(stplanr)

l1 = routes_fast_sf[2, ]
p1 = line2points(l1)
#> Warning in y_coords[d_indices] <- sapply(l_geometry, tail, n = 1): number of
#> items to replace is not a multiple of replacement length
b1 = sf::st_bbox(l1)
b2 = sf::st_bbox(p1)
identical(b1, b2)
#> [1] FALSE
b1
#>      xmin      ymin      xmax      ymax 
#> -1.535849 53.828200 -1.516748 53.830414
b2
#>      xmin      ymin      xmax      ymax 
#> -1.535849 -1.535849 -1.516748 53.828682
plot(l1$geometry)
plot(p1$geometry, add = TRUE)

sessionInfo()
#> R version 4.0.2 (2020-06-22)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04 LTS
#> 
#> Matrix products: default
#> BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-openmp/libopenblasp-r0.3.8.so
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=C             
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] stplanr_0.6.2 sf_0.9-5     
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.5         compiler_4.0.2     pillar_1.4.6       highr_0.8         
#>  [5] class_7.3-17       tools_4.0.2        digest_0.6.25      evaluate_0.14     
#>  [9] lifecycle_0.2.0    tibble_3.0.3       lattice_0.20-41    pkgconfig_2.0.3   
#> [13] rlang_0.4.7        igraph_1.2.5       DBI_1.1.0          curl_4.3          
#> [17] yaml_2.2.1         xfun_0.15          e1071_1.7-3        raster_3.3-13     
#> [21] dplyr_1.0.0        stringr_1.4.0      knitr_1.29         rgeos_0.5-3       
#> [25] generics_0.0.2     vctrs_0.3.2        classInt_0.4-3     grid_4.0.2        
#> [29] tidyselect_1.1.0   glue_1.4.1         R6_2.4.1           foreign_0.8-80    
#> [33] rmarkdown_2.3      sp_1.4-2           purrr_0.3.4        magrittr_1.5      
#> [37] codetools_0.2-16   maptools_1.0-1     htmltools_0.5.0    ellipsis_0.3.1    
#> [41] units_0.6-7        geosphere_1.5-10   KernSmooth_2.23-17 stringi_1.4.6     
#> [45] crayon_1.3.4

Created on 2020-07-27 by the reprex package (v0.3.0)

@agila5
Copy link
Collaborator

agila5 commented Jul 27, 2020

Hi everyone! I just wanted to report that I cannot reproduce the problem on windows with the same GDAL/PROJ/GEOS settings:

library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(stplanr)

l1 = routes_fast_sf[2, ]
p1 = line2points(l1)
b1 = sf::st_bbox(l1)
b2 = sf::st_bbox(p1)
b1
#>      xmin      ymin      xmax      ymax 
#> -1.535849 53.828200 -1.516748 53.830414
b2
#>      xmin      ymin      xmax      ymax 
#> -1.535849 53.828316 -1.516748 53.828682

Created on 2020-07-27 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.6.3 (2020-02-29)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  Italian_Italy.1252          
#>  ctype    Italian_Italy.1252          
#>  tz       Europe/Berlin               
#>  date     2020-07-27                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version    date       lib source                           
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.0)                   
#>  backports     1.1.8      2020-06-17 [1] CRAN (R 3.6.3)                   
#>  callr         3.4.3      2020-03-28 [1] CRAN (R 3.6.3)                   
#>  class         7.3-17     2020-04-26 [1] CRAN (R 3.6.3)                   
#>  classInt      0.4-3      2020-04-07 [1] CRAN (R 3.6.3)                   
#>  cli           2.0.2      2020-02-28 [1] CRAN (R 3.6.3)                   
#>  codetools     0.2-16     2018-12-24 [2] CRAN (R 3.6.3)                   
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.6.0)                   
#>  curl          4.3        2019-12-02 [1] CRAN (R 3.6.1)                   
#>  DBI           1.1.0      2019-12-15 [1] CRAN (R 3.6.3)                   
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.6.0)                   
#>  devtools      2.3.1      2020-07-21 [1] CRAN (R 3.6.3)                   
#>  digest        0.6.25     2020-02-23 [1] CRAN (R 3.6.3)                   
#>  dplyr         1.0.0      2020-05-29 [1] CRAN (R 3.6.3)                   
#>  e1071         1.7-3      2019-11-26 [1] CRAN (R 3.6.1)                   
#>  ellipsis      0.3.1      2020-05-15 [1] CRAN (R 3.6.3)                   
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 3.6.0)                   
#>  fansi         0.4.1      2020-01-08 [1] CRAN (R 3.6.2)                   
#>  foreign       0.8-75     2020-01-20 [2] CRAN (R 3.6.3)                   
#>  fs            1.4.2      2020-06-30 [1] CRAN (R 3.6.3)                   
#>  generics      0.0.2      2018-11-29 [1] CRAN (R 3.6.0)                   
#>  geosphere     1.5-10     2019-05-26 [1] CRAN (R 3.6.1)                   
#>  glue          1.4.1      2020-05-13 [1] CRAN (R 3.6.3)                   
#>  highr         0.8        2019-03-20 [1] CRAN (R 3.6.0)                   
#>  htmltools     0.5.0      2020-06-16 [1] CRAN (R 3.6.3)                   
#>  igraph        1.2.5      2020-03-19 [1] CRAN (R 3.6.3)                   
#>  KernSmooth    2.23-17    2020-04-26 [1] CRAN (R 3.6.3)                   
#>  knitr         1.29       2020-06-23 [1] CRAN (R 3.6.3)                   
#>  lattice       0.20-41    2020-04-02 [1] CRAN (R 3.6.3)                   
#>  lifecycle     0.2.0      2020-03-06 [1] CRAN (R 3.6.2)                   
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.6.0)                   
#>  maptools      1.0-1      2020-05-14 [1] CRAN (R 3.6.3)                   
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.6.0)                   
#>  pillar        1.4.6      2020-07-10 [1] CRAN (R 3.6.3)                   
#>  pkgbuild      1.1.0      2020-07-13 [1] CRAN (R 3.6.3)                   
#>  pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 3.6.1)                   
#>  pkgload       1.1.0      2020-05-29 [1] CRAN (R 3.6.3)                   
#>  prettyunits   1.1.1      2020-01-24 [1] CRAN (R 3.6.2)                   
#>  processx      3.4.3      2020-07-05 [1] CRAN (R 3.6.3)                   
#>  ps            1.3.3      2020-05-08 [1] CRAN (R 3.6.3)                   
#>  purrr         0.3.4      2020-04-17 [1] CRAN (R 3.6.3)                   
#>  R6            2.4.1      2019-11-12 [1] CRAN (R 3.6.1)                   
#>  raster        3.3-13     2020-07-17 [1] CRAN (R 3.6.3)                   
#>  Rcpp          1.0.5      2020-07-06 [1] CRAN (R 3.6.3)                   
#>  remotes       2.2.0      2020-07-21 [1] CRAN (R 3.6.3)                   
#>  rgeos         0.5-3      2020-05-08 [1] CRAN (R 3.6.3)                   
#>  rlang         0.4.7      2020-07-09 [1] CRAN (R 3.6.3)                   
#>  rmarkdown     2.3        2020-06-18 [1] CRAN (R 3.6.3)                   
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.6.0)                   
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                   
#>  sf          * 0.9-5      2020-07-14 [1] CRAN (R 3.6.3)                   
#>  sp            1.4-2      2020-05-20 [1] CRAN (R 3.6.3)                   
#>  stplanr     * 0.6.2      2020-07-08 [1] CRAN (R 3.6.3)                   
#>  stringi       1.4.6      2020-02-17 [1] CRAN (R 3.6.2)                   
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.6.0)                   
#>  testthat      2.3.2      2020-03-02 [1] CRAN (R 3.6.3)                   
#>  tibble        3.0.3.9000 2020-07-12 [1] Github (tidyverse/tibble@a57ad4a)
#>  tidyselect    1.1.0      2020-05-11 [1] CRAN (R 3.6.3)                   
#>  units         0.6-7      2020-06-13 [1] CRAN (R 3.6.3)                   
#>  usethis       1.6.1      2020-04-29 [1] CRAN (R 3.6.3)                   
#>  vctrs         0.3.2      2020-07-15 [1] CRAN (R 3.6.3)                   
#>  withr         2.2.0      2020-04-20 [1] CRAN (R 3.6.3)                   
#>  xfun          0.16       2020-07-24 [1] CRAN (R 3.6.3)                   
#>  yaml          2.2.1      2020-02-01 [1] CRAN (R 3.6.2)                   
#> 
#> [1] C:/Users/Utente/Documents/R/win-library/3.6
#> [2] C:/Program Files/R/R-3.6.3/library

@Robinlovelace
Copy link
Member

Interesting, the plot thickens. Many thanks for testing @agila5. This supports my view that it's an edge case that will not affect most users.

@G-dT
Copy link
Author

G-dT commented Jul 27, 2020

Several hours later, I have a brand new RStudio running in an Ubuntu virtual box on a different Windows PC running a different version of Windows.... and the same error.

library(sf)
library(stplanr)

l1 = routes_fast_sf[2, ]
p1 = line2points(l1)
Warning message:
In y_coords[d_indices] <- sapply(l_geometry, tail, n = 1) :
number of items to replace is not a multiple of replacement length
b1 = sf::st_bbox(l1)
b2 = sf::st_bbox(p1)
identical(b1, b2)
[1] FALSE

b1
xmin ymin xmax ymax
-1.535849 53.828200 -1.516748 53.830414
b2
xmin ymin xmax ymax
-1.535849 -1.535849 -1.516748 53.828682

sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] stplanr_0.6.2 sf_0.9-5

loaded via a namespace (and not attached):
[1] igraph_1.2.5 Rcpp_1.0.5 raster_3.3-13
[4] magrittr_1.5 maptools_1.0-1 units_0.6-7
[7] tidyselect_1.1.0 lattice_0.20-41 geosphere_1.5-10
[10] R6_2.4.1 rlang_0.4.7 dplyr_1.0.0
[13] tools_4.0.2 grid_4.0.2 KernSmooth_2.23-17
[16] e1071_1.7-3 DBI_1.1.0 rgeos_0.5-3
[19] ellipsis_0.3.1 class_7.3-17 tibble_3.0.3
[22] lifecycle_0.2.0 crayon_1.3.4 purrr_0.3.4
[25] codetools_0.2-16 vctrs_0.3.2 curl_4.3
[28] glue_1.4.1 sp_1.4-2 compiler_4.0.2
[31] pillar_1.4.6 generics_0.0.2 classInt_0.4-3
[34] foreign_0.8-79 pkgconfig_2.0.3

@G-dT
Copy link
Author

G-dT commented Jul 28, 2020

Re Linux - @Robinlovelace which relevant OS packages (if any) did you build from source? Did you pull all of them from the Ubuntu 20.04 repos? Did you pull anything from any other 3rd party repos? My husband has built libgeo, libproj and libgdal from source since the 18.04 repos have older versions of these than you listed.

@Robinlovelace
Copy link
Member

Re Linux - @Robinlovelace which relevant OS packages (if any) did you build from source? Did you pull all of them from the Ubuntu 20.04 repos? Did you pull anything from any other 3rd party repos?

All good questions. If you want the up-to-date stack now use the ubuntugis-unstable PPA on 18.04. Details: rocker-org/geospatial#31 (comment)

@G-dT
Copy link
Author

G-dT commented Jul 28, 2020

Still no joy.

Output:

library(sf)
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
library(stplanr)

l1 = routes_fast_sf[2, ]
p1 = line2points(l1)
Warning message:
In y_coords[d_indices] <- sapply(l_geometry, tail, n = 1) :
number of items to replace is not a multiple of replacement length
p1
Simple feature collection with 2 features and 1 field
geometry type: POINT
dimension: XY
bbox: xmin: -1.535849 ymin: -1.535849 xmax: -1.516748 ymax: 53.82868
geographic CRS: WGS 84
id geometry
1 1 POINT (-1.516748 53.82868)
2 1 POINT (-1.535849 -1.535849)

sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
[1] LC_CTYPE=en_GB.UTF-8
[2] LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8
[4] LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_GB.UTF-8
[6] LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=en_GB.UTF-8
[8] LC_NAME=C
[9] LC_ADDRESS=C
[10] LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8
[12] LC_IDENTIFICATION=C

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

other attached packages:
[1] stplanr_0.6.2 sf_0.9-5

loaded via a namespace (and not attached):
[1] igraph_1.2.5 Rcpp_1.0.5
[3] raster_3.3-13 magrittr_1.5
[5] maptools_1.0-1 units_0.6-7
[7] tidyselect_1.1.0 lattice_0.20-41
[9] geosphere_1.5-10 R6_2.4.1
[11] rlang_0.4.7 dplyr_1.0.0
[13] tools_4.0.2 grid_4.0.2
[15] KernSmooth_2.23-17 e1071_1.7-3
[17] DBI_1.1.0 rgeos_0.5-3
[19] ellipsis_0.3.1 class_7.3-17
[21] tibble_3.0.3 lifecycle_0.2.0
[23] crayon_1.3.4 purrr_0.3.4
[25] codetools_0.2-16 vctrs_0.3.2
[27] curl_4.3 glue_1.4.1
[29] sp_1.4-2 compiler_4.0.2
[31] pillar_1.4.6 generics_0.0.2
[33] classInt_0.4-3 foreign_0.8-79
[35] pkgconfig_2.0.3
attached base packages:
[1] stats graphics grDevices utils
[5] datasets methods base

other attached packages:
[1] stplanr_0.6.2 sf_0.9-5

loaded via a namespace (and not attached):
[1] igraph_1.2.5 Rcpp_1.0.5
[3] raster_3.3-13 magrittr_1.5
[5] maptools_1.0-1 units_0.6-7
[7] tidyselect_1.1.0 lattice_0.20-41
[9] geosphere_1.5-10 R6_2.4.1
[11] rlang_0.4.7 dplyr_1.0.0
[13] tools_4.0.2 grid_4.0.2
[15] KernSmooth_2.23-17 e1071_1.7-3
[17] DBI_1.1.0 rgeos_0.5-3
[19] ellipsis_0.3.1 class_7.3-17
[21] tibble_3.0.3 lifecycle_0.2.0
[23] crayon_1.3.4 purrr_0.3.4
[25] codetools_0.2-16 vctrs_0.3.2
[27] curl_4.3 glue_1.4.1
[29] sp_1.4-2 compiler_4.0.2
[31] pillar_1.4.6 generics_0.0.2
[33] classInt_0.4-3 foreign_0.8-79
[35] pkgconfig_2.0.3 `

@Robinlovelace
Copy link
Member

Heads-up @G-dT I've finally fixed it by using lwgeom 🎉

~Sorry for the delay. Please test. If you've any further comments/suggestions on this issue or any others please let me know.

Reproducible example of problem on set-up that was failing previously:

remotes::install_github("ropensci/stplanr")
#> Using github PAT from envvar GITHUB_PAT
#> Skipping install of 'stplanr' from a github remote, the SHA1 (7a0907a5) has not changed since last install.
#>   Use `force = TRUE` to force installation
library(stplanr)
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
l <- routes_fast_sf[2, ]
lpoints <- line2points(l)
plot(l$geometry)
plot(lpoints, add = TRUE)

# test all vertices:
plot(l$geometry)
lpoints2 <- line2pointsn(l)
plot(lpoints2$geometry, add = TRUE)

Created on 2020-08-25 by the reprex package (v0.3.0)

@G-dT
Copy link
Author

G-dT commented Aug 26, 2020

Thank you! That works on my main machine.
I'll try to check it later on the other two where it was also not working and let you know.

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

3 participants