View source: R/get_shapes_df.R
get_shapes_df | R Documentation |
The 'get_shapes_df' function converts a spatial object of shapes (with geometry) into a GTFS-compliant 'shapes' data frame format, detailing latitude, longitude, point sequence, and cumulative distance traveled along each shape.
get_shapes_df(shape)
shape |
A spatial ('sf') object containing shapes, with 'shape_id' and geometry information. |
The function performs the following steps:
- Validates that the 'shape' object is of class 'sf' and contains a 'shape_id' column.
- Extracts point coordinates from each shape’s geometry, creating a sequence of latitude and longitude points.
- Computes cumulative distances along the shape, using Euclidean distance between consecutive points.
The resulting data frame conforms to the GTFS 'shapes.txt' format. Distances are expressed in meters.
A data frame with columns:
Unique identifier for each shape.
Longitude coordinates of each shape point.
Latitude coordinates of each shape point.
Sequence of points along each shape.
Cumulative distance traveled along the shape in meters.
[GTFSwizard::get_shapes()], [GTFSwizard::get_shapes_sf()]
# Convert a shape geometry to a GTFS-compliant shapes data frame
shape <- get_shapes_sf(for_rail_gtfs$shapes)
shapes_df <- get_shapes_df(shape = shape)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.