Inputs
I have two shapefiles that I Import into R, so that I end up with. A spatiallinesdataframe containing bus routes. A spatialpointsdataframe containing bus stops.
Plotting a given route with its stops looks like this.
Sample Data
This link includes two shapefiles to download as a zip with a sample two routes.
Target
My aim is to calculate the geographic distance in meters between every pair of stops: Stop 1 to Stop 2, Stop 2 to Stop 3, etc. across the length of the underlying bus route.
Most methods I found calculate the euclidean distance, or as 'the crow flies'; which will not work here.
This post mentions the PBSmapping
which has a calcLength
function that does a great job calculating the total distance of the route, but I can't find a way to match it to the stop pairs situation, nor can I find a way to actually subset the shapefile by its attributes.
The riverdist
package is equally interesting, but highly optimized for rivers that I can't find a way to apply it.
sf
withst_length
, but exactly how depends on the format of the lines and stops. – Calum You