Skip to content

Commit

Permalink
if stop doesn't exist in TIPLOC file - put tiploc code name into rout…
Browse files Browse the repository at this point in the history
…e name instead of NA
  • Loading branch information
oweno-tfwm committed Sep 22, 2023
1 parent 1b6e515 commit d889ee5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions R/atoc_export.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,16 @@ longnames <- function(routes, stop_times, stops) {
stop_times_sub,
dplyr::rename(stops[, c("stop_id", "stop_name")], stop_name_a = stop_name),
by = c("stop_id_a" = "stop_id"))

stop_times_sub <- dplyr::left_join(
stop_times_sub,
dplyr::rename(stops[, c("stop_id", "stop_name")], stop_name_b = stop_name),
by = c("stop_id_b" = "stop_id"))

stop_times_sub$route_long_name <- paste0("from ",
stop_times_sub$stop_name_a,
ifelse( is.na(stop_times_sub$stop_name_a), stop_times_sub$stop_id_a, stop_times_sub$stop_name_a),
" to ",
stop_times_sub$stop_name_b)
ifelse( is.na(stop_times_sub$stop_name_b), stop_times_sub$stop_id_b, stop_times_sub$stop_name_b) )

stop_times_sub$route_long_name <- gsub(" Rail Station", "" , stop_times_sub$route_long_name)

Expand Down
6 changes: 3 additions & 3 deletions R/atoc_nr.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ getCachedLocationData <- function(locations = "tiplocs")
if (inherits(locations, "sf"))
{
stops <- cbind(locations, sf::st_coordinates(locations))
stops <- as.data.frame(stops)
stops <- stops[, c( "stop_id", "stop_code", "stop_name", "Y", "X" )]
names(stops) <- c( "stop_id", "stop_code", "stop_name", "stop_lat", "stop_lon" )
stops <- sf::st_drop_geometry(stops)
stops <- as.data.table(stops)
setnames(stops, old = c("Y", "X"), new = c("stop_lat", "stop_lon"))
}
else #TODO test column names
{
Expand Down

0 comments on commit d889ee5

Please sign in to comment.