Learn R Programming

stplanr (version 0.6.2)

geo_toptail: Clip the first and last n metres of SpatialLines

Description

Takes lines and removes the start and end point, to a distance determined by the user.

Usage

geo_toptail(l, toptail_dist, ...)

Arguments

l

A SpatialLines object

toptail_dist

The distance (in metres) to top and tail the line by. Can either be a single value or a vector of the same length as the SpatialLines object.

...

Arguments passed to rgeos::gBuffer()

Details

Note: toptailgs() is around 10 times faster, but only works on data with geographic CRS's due to its reliance on the geosphere package.

See Also

Other lines: angle_diff(), is_linepoint(), line2df(), line2points(), line_bearing(), line_match(), line_midpoint(), line_sample(), line_segment(), line_via(), mats2line(), n_sample_length(), n_vertices(), onewaygeo(), onewayid(), points2line(), toptail_buff(), toptailgs(), update_line_geometry()

Examples

Run this code
# NOT RUN {
l <- routes_fast[2:4, ]
l_toptail <- geo_toptail(l, toptail_dist = 300)
plot(l)
plot(l_toptail, col = "red", add = TRUE, lwd = 3)
plot(cents, col = "blue", add = TRUE, pch = 15)
# Note the behaviour when the buffer size removes lines
r_toptail <- geo_toptail(l, toptail_dist = 900)
nrow(r_toptail)
plot(r_toptail, lwd = 9, add = TRUE) # short route removed
l <- sf::st_as_sf(l)
l_top_tail <- geo_toptail(l, 300)
l_top_tail
plot(sf::st_geometry(l_top_tail))
plot(sf::st_geometry(geo_toptail(l, 900)), lwd = 9, add = TRUE)
# }

Run the code above in your browser using DataLab