Skip to content

Commit 8323fef

Browse files
#82 create_shapes_from_sf adapted to new multiline_to_sorted_linestring points parameter using two first stops when linear geometry instead of just one
1 parent 848cfbb commit 8323fef

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

R/create_shapes_from_sf.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#' It first converts any MULTILINESTRING geometries to LINESTRING geometries using the
1313
#' \code{multiline_to_sorted_linestring}, using a point guide per shape:
1414
#' all ordered stops when the selected trip is circular (first and last
15-
#' \code{stop_id} are equal), or only the first stop otherwise.
15+
#' \code{stop_id} are equal), or the first two stops otherwise.
1616
#' Then, it converts the LINESTRING geometries to a data.table representing a GTFS shapes table using
1717
#' \code{gtfstools::convert_sf_to_shapes}.
1818
#'
@@ -68,7 +68,7 @@ create_shapes_from_sf <- function(
6868

6969
# Build point guides per shape
7070
# > circular trip: all stops in sequence
71-
# > non-circular trip: first stop only
71+
# > non-circular trip: first two stops
7272
trips_stops_sf <- gtfs$stop_times |>
7373
arrange(trip_id, stop_sequence) |>
7474
left_join(gtfs$trips |> select(trip_id, shape_id), by = "trip_id") |>
@@ -78,7 +78,7 @@ create_shapes_from_sf <- function(
7878
trips_points <- split(trips_stops_sf, trips_stops_sf$trip_id) |>
7979
lapply(function(trip_sf) {
8080
is_circular <- nrow(trip_sf) > 1 && trip_sf$stop_id[1] == trip_sf$stop_id[nrow(trip_sf)]
81-
trip_points <- if (is_circular) sf::st_geometry(trip_sf) else sf::st_geometry(trip_sf)[1]
81+
trip_points <- if (is_circular) sf::st_geometry(trip_sf) else sf::st_geometry(trip_sf)[seq_len(min(2, nrow(trip_sf)))]
8282

8383
data.frame(
8484
trip_id = trip_sf$trip_id[1],

0 commit comments

Comments
 (0)