Skip to contents

Convert the shapes of a GTFS data loaded using read_gtfs into a LINESTRING simple feature (sf) object, using convert_shapes_to_sf, and add the length of each shape in kilometres. The input data is not modified.

Usage

gtfs_shapes_as_sf(gtfs, crs = 4326)

Arguments

gtfs

A GTFS data. shape_id must be character and shape_pt_sequence integer, as produced by read_gtfs.

crs

The coordinate reference system of the output: an EPSG code, a string accepted by st_crs, or a crs object. Shapes are read as WGS84 (EPSG:4326) and transformed to crs. The default value is 4326 (no transformation). It must be a valid CRS: NA or an unknown CRS raises an error of class gtfs2gps_crs_error.

Value

A simple feature (sf) object with columns shape_id, geometry and length (km).

Examples

poa <- read_gtfs(system.file("extdata/saopaulo.zip", package = "gtfs2gps"))
#> Unzipped the following files to /tmp/Rtmppl8S8P/gtfsio:
#>   * agency.txt
#>   * calendar.txt
#>   * frequencies.txt
#>   * routes.txt
#>   * shapes.txt
#>   * stop_times.txt
#>   * stops.txt
#>   * trips.txt
#> Reading agency
#> Reading calendar
#> Reading frequencies
#> Reading routes
#> Reading shapes
#> Reading stop_times
#> Reading stops
#> Reading trips
poa_sf <- gtfs_shapes_as_sf(poa)