-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1st draft of new function merge_gtfs_feeds.R
- Loading branch information
1 parent
d07906c
commit 55eda53
Showing
5 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,6 @@ Imports: | |
utils, | ||
raster, | ||
pbapply | ||
RoxygenNote: 7.0.2 | ||
RoxygenNote: 7.1.0 | ||
VignetteBuilder: knitr | ||
LinkingTo: Rcpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#' @title Merge multiple GTFS feeds into a single one | ||
#' | ||
#' @description Build a single GTFS by joinning together the elements of multiple GTFS feeds. | ||
#' @param gtfs_list A list of GTFS.zip files. | ||
#' @return A single list of data.tables, where each index represents the respective GTFS file name. | ||
#' @export | ||
#' @examples | ||
#' | ||
#' # get a list of GTFS feeds | ||
#' spo <- system.file("extdata/saopaulo.zip", package = "gtfs2gps") | ||
#' poa <- system.file("extdata/poa.zip", package = "gtfs2gps") | ||
#' gtfs_list <- list(spo, poa) | ||
#' | ||
#' new_gtfs <- merge_gtfs_feeds(gtfs_list) | ||
#' | ||
|
||
merge_gtfs_feeds <- function(gtfs_list){ | ||
|
||
# read all fees separately | ||
all_feeds <- lapply(gtfs_list, read_gtfs) | ||
|
||
# separate 1st feed | ||
new_gtfs <- all_feeds[[2]] | ||
|
||
# function to extract elements in a series of lists | ||
extract_list_element <- function(i, element){ all_feeds[[i]][[element]] } | ||
|
||
|
||
## piling up | ||
|
||
# 1/8 agency | ||
new_gtfs$agency <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'agency') %>% rbindlist(fill=T) | ||
|
||
# 2/8 routes | ||
new_gtfs$routes <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'routes') %>% rbindlist(fill=T) | ||
|
||
# 3/8 stops | ||
new_gtfs$stops <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'stops') %>% rbindlist(fill=T) | ||
|
||
# 4/8 stop_times | ||
new_gtfs$stop_times <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'stop_times') %>% rbindlist(fill=T) | ||
|
||
# 5/8 shapes | ||
new_gtfs$shapes <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'shapes') %>% rbindlist(fill=T) | ||
|
||
# 6/8 trips | ||
new_gtfs$trips <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'trips') %>% rbindlist(fill=T) | ||
|
||
# 7/8 calendar | ||
new_gtfs$calendar <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'calendar') %>% rbindlist(fill=T) | ||
|
||
# 8/8 frequencies | ||
new_gtfs$frequencies <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'frequencies') %>% rbindlist(fill=T) | ||
|
||
return(new_gtfs) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#' @title Merge multiple GTFS feeds into a single one | ||
#' | ||
#' @description Build a single GTFS by joinning together the elements of multiple GTFS feeds. | ||
#' @param gtfs_list A list of GTFS.zip files. | ||
#' @return A single list of data.tables, where each index represents the respective GTFS file name. | ||
#' @export | ||
#' @examples | ||
#' | ||
#' # get a list of GTFS feeds | ||
#' spo <- system.file("extdata/saopaulo.zip", package = "gtfs2gps") | ||
#' poa <- system.file("extdata/poa.zip", package = "gtfs2gps") | ||
#' gtfs_list <- list(spo, poa) | ||
#' | ||
#' new_gtfs <- merge_gtfs_feeds(gtfs_list) | ||
#' | ||
|
||
merge_gtfs_feeds <- function(gtfs_list){ | ||
|
||
# read all fees separately | ||
all_feeds <- lapply(gtfs_list, read_gtfs) | ||
|
||
# separate 1st feed | ||
new_gtfs <- all_feeds[[2]] | ||
|
||
# function to extract elements in a series of lists | ||
extract_list_element <- function(i, element){ all_feeds[[i]][[element]] } | ||
|
||
|
||
## piling up | ||
|
||
# 1/8 agency | ||
new_gtfs$agency <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'agency') %>% rbindlist(fill=T) | ||
|
||
# 2/8 routes | ||
new_gtfs$routes <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'routes') %>% rbindlist(fill=T) | ||
|
||
# 3/8 stops | ||
new_gtfs$stops <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'stops') %>% rbindlist(fill=T) | ||
|
||
# 4/8 stop_times | ||
new_gtfs$stop_times <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'stop_times') %>% rbindlist(fill=T) | ||
|
||
# 5/8 shapes | ||
new_gtfs$shapes <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'shapes') %>% rbindlist(fill=T) | ||
|
||
# 6/8 trips | ||
new_gtfs$trips <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'trips') %>% rbindlist(fill=T) | ||
|
||
# 7/8 calendar | ||
new_gtfs$calendar <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'calendar') %>% rbindlist(fill=T) | ||
|
||
# 8/8 frequencies | ||
new_gtfs$frequencies <- lapply(X=1:length(all_feeds), FUN = extract_list_element, 'frequencies') %>% rbindlist(fill=T) | ||
|
||
return(new_gtfs) | ||
} |