17 Smoothing a Route
If we have a route made up from a set of points, we find an smooth trajectory through them using a function such as a the smoothr::smooth()
function. The trajr
package also has a smoothing function in the form of TrajSmoothSG()
.
= smoothr::smooth(stage_route_utm,
smooth_route_utm method = "ksmooth")
We can preview the route to on an interactive map so we can zoom in to see where the smooth route might diverge from the provided route.
= st_transform(smooth_route_utm,
smooth_route crs = st_crs(original_crs)) %>% st_coordinates()
= smooth_route[,1:2]
smooth_route
= st_transform(stage_route_utm,
official_route crs = st_crs(original_crs)) %>% st_coordinates()
= official_route[,1:2]
official_route
leaflet(smooth_route) %>%
addProviderTiles("OpenTopoMap", group = "OSM") %>%
addPolylines()
However, the smoothing is based on being provided with an actual route. If we have data from multiple drivers representing multiple routes, whilst we can visualise the route as a set of points and “see” the route they tend to follow, it’s hard to see a priori how we might order those points into an approximate route given that the distance along route may vary slightly and the time along route at particular locations is also likely to vary.
Thinking a bit more ecologically, we might perhaps consider a group of animals following the same (ish) path over a period of time and then trying to work out the route they take from those separate sets of sample data. How do the ecologists do that?
If we know the start and end of the route are nominally at the same location, we can normalise the route length of multiple routes, map equidistant points onto each other, and then take the average. For example, this solution: https://stackoverflow.com/a/65341730/454773 . See also https://en.wikipedia.org/wiki/Dynamic_time_warping and https://dynamictimewarping.github.io/r/ .