Setup

This script is meant to be run after QGIS 2.x.x is used to generate paths from the timeseries data generated in the previous script. The older version of QGIS is necessary to use the Points to Paths plugin, which allows for separate lines per vertex (important because we define each 15-minute interval as a distinct trip, even if movement was detected over several consecutive intervals). Within the plugin, bike IDs and row numbers were concatenated using field calculator in order to create a movement ID, which was used to define a trip as a movement of over 50 meters within 15 minutes to account for GPS variability on scooters.

flow_lines <- st_read("../../results/trip_id_p2p.shp")
trip_id_long <- st_read("../../results/trip_id_long.gpkg")
flow_lines_proj <- flow_lines %>% st_transform(4326)

We use lwgeom to define the start and endpoints of each of our flow lines, so we have a directionality for our trips

flow_lines$start_geom <- st_startpoint(flow_lines)
flow_lines$end_geom <- st_endpoint(flow_lines)
flow_lines_proj$start_geom <- st_startpoint(flow_lines_proj)
flow_lines_proj$end_geom <- st_endpoint(flow_lines_proj)

Since almost all spatial file formats require only one geometry column, we write to an RDS file to preserve our geometries (for starts and ends, and in the next script for hexagon data as well).

flow_lines <- flow_lines %>% mutate(dist = st_length(geometry))
summarise(flow_lines, mean = mean(dist))
saveRDS(object = flow_lines, file = "../../results/flow_lines.RDS", compress = FALSE)