View source: R/get_trip_geometry.R
| get_trip_geometry | R Documentation |
Returns the geometry of each specified trip_id, from its first to its last
stop, either along the trip's shape or as straight lines between stops.
get_trip_geometry(
gtfs,
trip_id = NULL,
method = "shapes",
crs = 4326,
sort_sequence,
file = NULL
)
gtfs |
A GTFS object, as created by |
trip_id |
A character vector including the |
method |
A string, either |
crs |
The CRS of the resulting object, either as an EPSG code or as an
|
sort_sequence |
Deprecated; do not supply. Timetables and shapes are
now always sorted by |
file |
Deprecated. Use |
A LINESTRING sf with the trip_id and the geometry of each trip
listed in stop_times.
With method = "shapes", the first and last stops of each trip are
projected onto its shape, as in get_trip_length(), and the geometry is the
part of the shape between them. Thus, its length matches the length
returned by get_trip_length() (when this length is not NA, see below),
and the limitations described there apply. Trips whose stops are all
located at the same point of the shape get a zero-length geometry.
Use get_shapes_geometry() for the geometry of entire shapes.
With method = "euclidean", the geometry links the consecutive stops of
each trip along straight lines (stops' coordinates are retrieved from the
stops table), so its resolution tends to be much lower than that of the
geometry generated from the shapes. Trips with a single stop get a
single-point geometry.
Both methods ignore stops with missing coordinates, or not listed in
stops (for which get_trip_length() returns NA lengths). Trips
without any stop with coordinates get an empty geometry, as do, with
method = "shapes", trips with fewer than two stops with coordinates or
not linked to a shape with at least two distinct points (the
latter with a warning). Geometries along shapes that cross the antimeridian
are not handled correctly.
get_trip_length(), get_shapes_geometry()
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)
# geometry along the shape from the first to the last stop of each trip
trip_geometry <- get_trip_geometry(gtfs)
head(trip_geometry)
# straight lines between consecutive stops
trip_ids <- c("CPTM L07-0", "2002-10-0")
straight_geometry <- get_trip_geometry(
gtfs,
trip_id = trip_ids,
method = "euclidean"
)
straight_geometry
plot(straight_geometry["trip_id"])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.