get_trip_length: Get trip length

View source: R/get_trip_length.R

get_trip_lengthR Documentation

Get trip length

Description

Returns the length of each specified trip_id, based either on the shapes or the stop_times file (or both).

Usage

get_trip_length(gtfs, trip_id = NULL, file = NULL, unit = "km")

Arguments

gtfs

A GTFS object, as created by read_gtfs().

trip_id

A character vector including the trip_ids to have their length calculated If NULL (the default), the function calculates the length of each trip_id in the GTFS.

file

A character vector specifying the file from which lengths should be calculated (either one of or both shapes and stop_times). If NULL (the default), the function attempts to calculate the lengths from both files, but only raises an error if none of the files exist.

unit

A string representing the unit in which lengths are desired. Either "km" (the default) or "m".

Value

A data.table containing the length of each specified trip.

Details

Please check get_trip_geometry() documentation to understand how geometry generation, and consequently length calculation, differs depending on the chosen file.

Examples

data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")

gtfs <- read_gtfs(data_path)

trip_length <- get_trip_length(gtfs)
head(trip_length)

# the above is identical to
trip_length <- get_trip_length(gtfs, file = c("shapes", "stop_times"))
head(trip_length)

trip_ids <- c("CPTM L07-0", "2002-10-0")
trip_length <- get_trip_length(gtfs, trip_id = trip_ids)
trip_length


gtfstools documentation built on Nov. 24, 2022, 5:09 p.m.