I've been moving most of my workflow to using the sf package in R, and I'm trying to find the equivalent to the maptools package SpatialLinesMidPoints function - I've used this function frequently over the years and had modified to get line endpoints as well (here).
Is there an equivalent function using sf package? I've looked at st_cast and st_line_sample, but want to explicitly get midpoints of lines. I'm guessing perhaps I can make use of either st_cast or st_line_sample with slight modification to get just midpoints but struggling a bit with approach.
Just to be explicit, I'm looking for equivalent of doing:
library(spData) library(maptools) library(sf) seine <- as(seine, 'Spatial') seine_midpoints <- SpatialLinesMidPoints(seine) # To verify: plot(seine, axes=T) plot(seine_midpoints, add=T, col='red')