Closed Robinlovelace closed 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)
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)
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
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!
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:
An sf object with one feature containing a linestring geometry to be split
A point represented by an sf object the will split the route
However, as this is a replacement for st_nearest_feature there is no splitting involved, right?