-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from r-transit/dev/geojson_update_reference
Handle locations.geojson and update specs
- Loading branch information
Showing
33 changed files
with
373 additions
and
504 deletions.
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
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,38 @@ | ||
#' Convert columns between gtfsio types to tidytransit types according to GTFS reference | ||
#' | ||
#' @param gtfs_list gtfs object | ||
#' @param conversion_table data.frame containing a column `file` and `Field_Name`, generally | ||
#' from internal `gtfs_reference_types` dataset | ||
#' @param conversion_function function to convert columns | ||
#' | ||
#' @return gtfs_list with converted (overwritten) columns in tables | ||
#' | ||
convert_types <- function(gtfs_list, conversion_table, conversion_function) { | ||
for(i in seq_len(nrow(conversion_table))) { | ||
file = conversion_table$file[i] | ||
field_name = conversion_table$Field_Name[i] | ||
if(feed_contains(gtfs_list, file)) { | ||
if(!is.null(gtfs_list[[file]][[field_name]])) { | ||
stopifnot(inherits(gtfs_list[[file]], "data.table")) | ||
gtfs_list[[file]][, c(field_name) := conversion_function(get(field_name))] | ||
} | ||
} | ||
} | ||
return(gtfs_list) | ||
} | ||
|
||
convert_char_to_date <- function(gtfs_list) { | ||
convert_types(gtfs_list, gtfs_reference_types$Date, .parse_gtfsio_date) | ||
} | ||
|
||
convert_date_to_char <- function(gtfs_obj) { | ||
convert_types(gtfs_obj, gtfs_reference_types$Date, .date_as_gtfsio_char) | ||
} | ||
|
||
convert_char_to_hms <- function(gtfs_list) { | ||
convert_types(gtfs_list, gtfs_reference_types$Time, hhmmss_to_hms) | ||
} | ||
|
||
convert_hms_to_char <- function(gtfs_obj) { | ||
convert_types(gtfs_obj, gtfs_reference_types$Time, hms_to_hhmmss) | ||
} |
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
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,24 @@ | ||
#' Convert a tidygtfs object to a gtfs object (for gtfsio) | ||
#' | ||
#' @param gtfs_obj gtfs feed (tidygtfs object) | ||
#' @return gtfs list | ||
#' @keywords internal | ||
tidygtfs_to_gtfs = function(gtfs_obj) { | ||
# convert sf tables | ||
gtfs_obj <- sf_as_tbl(gtfs_obj) | ||
gtfs_obj <- sf_as_json(gtfs_obj) | ||
|
||
# convert NA to empty strings | ||
gtfs_obj <- na_to_empty_strings(gtfs_obj) | ||
|
||
# data.tables | ||
gtfs_obj <- gtfs_obj[names(gtfs_obj) != "."] | ||
gtfs_obj <- convert_list_tables_to_data.tables(gtfs_obj) | ||
class(gtfs_obj) <- list("gtfs") | ||
|
||
# convert dates/times to strings | ||
gtfs_obj <- convert_date_to_char(gtfs_obj) | ||
gtfs_obj <- convert_hms_to_char(gtfs_obj) | ||
|
||
return(gtfs_obj) | ||
} |
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
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
Oops, something went wrong.