Create single line for transit lines using gtfs data and R

147 views Asked by At

I am using the tidytransit package in R to create some files for some geospatial analysis and mapmaking. I have successfully gotten the route geometries using the following code:

library(tidytransit)
library(tidyverse)
library(sf)
library(tmap)

########################## Load GTFS ###################################
gtfs = read_gtfs("https://www.riderta.com/sites/default/files/gtfs/latest/google_transit.zip")
gtfs_sf = gtfs_as_sf(gtfs)
routes = get_route_geometry(gtfs_sf) 

I map it using this code:

########### quick map ########################
tmap_mode("view")
qtm(routes)

Here is a screenshot of a section of the resulting map.

enter image description here

You'll notice that there is not a single line (visually)- but the linestring objects in the resulting shapefile contain both the east and westbound trip in one line object. This makes the maps look less aesthetically pleasing.

Does anyone know of a better way to do this? Ideally, I would like to just have one visually appearing line for each of the routes. My thought was to simply take one direction of the trips, but this creates additional issues because the routes turn around in loops, so portions of the route become missing. In other words, I don't want the lines to appear as taking both the eastbound and westbound lanes on the highway.

Thank you very much!

0

There are 0 answers