selection | R Documentation |
The “selection” function makes a selection in the GTFS file without altering or filtering the GTFS file.
selection(gtfs, ..., add = FALSE)
unselection(gtfs)
gtfs |
An object representing GTFS data. It can be a list or a 'wizardgtfs' class gtfsect. |
... |
Expressions used to filter the data within 'gtfs'. The expressions can operate on four GTFS variables:
|
add |
A logical argument. If 'TRUE', appends the new selection to existing ones in the gtfsect; otherwise, creates a new selection. |
The function evaluates the provided expressions in an environment restricted to recognized variables ('stop_id', 'route_id', 'trip_id', 'geometry'). An error is thrown if an unrecognized variable is used, indicating that only specific variables are allowed.
A 'wizardgtfs_selected' wizardgtfs, which is a modified version of the original attributes with the selections applied. If the expression yields no matches, returns the original gtfs unchanged.
# Apply the selection function
result <- selection(for_rail_gtfs,
stop_id == for_rail_gtfs$stops$stop_id[1] & trip_id %in% for_rail_gtfs$trips$trip_id[1:5])
# Check the selection
class(result)
attr(result, 'selection')
# Use geometry selection
bbox <- sf::st_bbox(c(
xmin = -38.57219059002416,
ymin = -3.7999496173114118,
xmax = -38.50455165901261,
ymax = -3.756631724636505
),
crs = sf::st_crs(4326)) # Set CRS to WGS 84
# Convert the bounding box to a polygon
polygon <- sf::st_as_sfc(bbox)
result <- selection(for_rail_gtfs, geometry %intersects% polygon)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.