ropensci / stplanr

Sustainable transport planning with R
https://docs.ropensci.org/stplanr
Other
422 stars 66 forks source link

Bug in line2vertices when line is composed by 2 points #432

Closed agila5 closed 4 years ago

agila5 commented 4 years ago

Reprex:

# upgrade packages
remotes::install_github("ropensci/stplanr")
#> Skipping install of 'stplanr' from a github remote, the SHA1 (f3c6c8d2) has not changed since last install.
#>   Use `force = TRUE` to force installation

# packages
library(sf)
#> Linking to GEOS 3.7.1, GDAL 2.2.2, PROJ 4.9.2
library(stplanr)

# fake data
my_fake_linestring <- st_sf(
  data.frame(x = c(1, 2)), 
  geometry = st_sfc(
    st_linestring(rbind(c(0, 0), c(1, 0), c(2, 0))), 
    st_linestring(rbind(c(1, 0), c(1, 1)))
  )
)
plot(my_fake_linestring)

line2vertices(my_fake_linestring)
#> Error in `[.data.frame`(x, coords): undefined columns selected

Created on 2020-10-05 by the reprex package (v0.3.0)

Taken from https://github.com/luukvdmeer/sfnetworks/issues/73. It should be easy to fix and I'm working on a PR

Robinlovelace commented 4 years ago

Many thanks @agila5, I never came across that edge case, great it now works for straight lines with only 2 points.