ropensci / stplanr

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

Issue in documentation #431

Closed Robinlovelace closed 4 years ago

Robinlovelace commented 4 years ago

Via email:

I found a small mistake in your reference manual for stplanr: https://cran.r-project.org/web/packages/stplanr/index.html

The argument text of “route_nearest_point” does not match the behaviour of the function.

It says:

However, as this is a replacement for st_nearest_feature there is no splitting involved, right?

MTueting commented 4 years ago

Reference Manual p. 84:

Description This function was written as a drop-in replacement for sf::st_nearest_feature(), which only works with recent versions of GEOS.

Usage route_nearest_point(r, p, id_out = FALSE)

Arguments r An sf object with one feature containing a linestring geometry to be split p A point represented by an sf object the will split the route id_out Should the index of the matching feature be returned? FALSE by default

The function does indeed work similar to sf::st_nearest_feature (if id_out = TRUE)

library(stplanr)
library(sf)
library(dplyr)

r <- routes_fast_sf[2:6, NULL]
p <- sf::st_sfc(sf::st_point(c(-1.540, 53.826)), crs = sf::st_crs(r))
route_nearest_point(r, p, id_out = TRUE)
r_nearest <- route_nearest_point(r, p)
plot(r$geometry)
plot(p, add = TRUE)
plot(r_nearest, lwd = 5, add = TRUE)

# Similar to st_nearest_feature

st_nearest_feature(p, r)
r_nearest <- r[st_nearest_feature(p, r),]
plot(r$geometry)
plot(p, add = TRUE)
plot(r_nearest, lwd = 5, add = TRUE)

Rplot1

However, the argument section suggests that the function does some sort of splitting, similar to stplanr::route_split()

r_split <- route_split(r_nearest, p)

# Only for visual purposes
r_split <- r_split %>% mutate(n = 1:n())

plot(r$geometry)
plot(p, add = TRUE)
plot(r_split[2], lwd = 5, add = TRUE)

Rplot2

In my opinion the attribute description for r and p should be something like: Arguments r An sf object containing linestrings p A point represented by an sf object for which the nearest linestring will be found id_out Should the index of the matching feature be returned? FALSE by default

Robinlovelace commented 4 years ago

Heads-up @MTueting I think the issue is fixed now. Please check the code changed in the commit above. Any further issues, please let me know. Many thanks!