View source: R/convert_stops_to_shapes.R
| convert_stops_to_shapes | R Documentation |
Creates shapes for the given trips, linking their consecutive stops along straight lines, and assigns them to the trips. Useful for feeds without shapes, or in which some trips are not linked to a shape.
convert_stops_to_shapes(gtfs, trip_id = NULL)
gtfs |
A GTFS object, as created by |
trip_id |
A character vector including the |
The GTFS object passed to the gtfs parameter, with the new shapes
added to the shapes table (created if needed) and assigned to the trips
in the trips table.
The shape of a trip links its stops, in stop_sequence order, along
straight lines. Stops without coordinates, or not listed in stops, are
skipped. Trips that visit the same sequence of stops share the same shape.
The new shapes get new shape_ids ("stops_shape_1", "stops_shape_2",
etc.), different from any shape_id already listed in shapes or trips.
Their shape_dist_traveled is not calculated, because the distance unit
used by the feed is unknown, and the shape_dist_traveled of the
stop_times entries of the trips that get new shapes, if present, is set
to NA. Shapes no longer used by any trip are kept (please use
remove_unused_ids() to remove them).
A shape is usable if it has at least two distinct points with coordinates.
With trip_id = NULL, the trips that get new shapes are those not linked
to a shape_id, or linked to a shape_id that is not listed in shapes
or whose shape is not usable (all trips, if the feed doesn't have a
shapes table). These are the trips that get_trip_length() and
get_trip_geometry() can't measure along a shape.
Trips with fewer than two distinct stops with coordinates, or without
stop_times entries, can't get a usable shape, so they keep their current
shape_id, with a warning.
get_trip_geometry(), convert_sf_to_shapes(),
remove_unused_ids()
library(dplyr)
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)
# a feed without shapes gets one shape for each sequence of stops
gtfs$shapes <- NULL
new_gtfs <- convert_stops_to_shapes(gtfs)
head(new_gtfs$shapes)
new_gtfs$trips |>
select(trip_id, shape_id) |>
head()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.