Learn R Programming

stplanr (version 0.5.0)

route_nearest_point: Find nearest route to a given point

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

Examples

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab