Learn R Programming

gtfstools (version 2.0.1)

get_shape_length: Get shape length

Description

Returns the length of each specified shape_id, from its first to its last point.

Usage

get_shape_length(gtfs, shape_id = NULL, unit = "km")

Value

A data.table with the shape_id and the length of each shape.

Arguments

gtfs

A GTFS object, as created by read_gtfs().

shape_id

A character vector including the shape_ids to have their length calculated. If NULL (the default), the function calculates the length of every shape_id in the GTFS.

unit

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

Details

The points of each shape are sorted by shape_pt_sequence before the length is calculated. Lengths are great-circle distances calculated with the haversine formula, on a sphere with the same radius used by {s2} (6,371,010 meters), regardless of whether sf::sf_use_s2() is enabled. Shapes with any point with missing coordinates have NA lengths.

A trip usually travels only part of its shape, from its first to its last stop. Use get_trip_length() to calculate the length of the trips.

See Also

get_trip_length()

Examples

Run this code
# \dontshow{
  old_dt_threads <- data.table::setDTthreads(1)
  on.exit(data.table::setDTthreads(old_dt_threads), add = TRUE)
# }
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)

shape_length <- get_shape_length(gtfs)
head(shape_length)

shape_length <- get_shape_length(gtfs, c("17846", "68962"), unit = "m")
shape_length

Run the code above in your browser using DataLab