Skip to content

Commit

Permalink
update weight_streetnet.sc for bicycle routing #207
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Apr 27, 2023
1 parent 89eeed1 commit 9dfbe61
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dodgr
Title: Distances on Directed Graphs
Version: 0.2.20.003
Version: 0.2.20.004
Authors@R: c(
person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre")),
person("Andreas", "Petutschnig", role = "aut"),
Expand Down
4 changes: 3 additions & 1 deletion R/graph-functions-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ find_d_col <- function (graph) {
tolower (substring (names (graph), 2, 2)) != "_"
)
if (length (d_col) != 1) {
d_col <- which (tolower (substring (names (graph), 1, 2)) == "di")
d_nms <- names (graph) [d_col]
d_col <- d_col [which (nchar (d_nms) == 1 |
tolower (substring (d_nms, 1L, 4L)) == "dist")]
}

if (length (d_col) != 1) {
Expand Down
9 changes: 8 additions & 1 deletion R/weight-streetnet-times.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,16 @@ extract_sc_edges_highways <- function (graph, x, wt_profile, wt_profile_file,
keep_cols <- c (keep_cols, unique (surface$key))
}

if (length (keep_cols) > 0L) {

keys <- unique (x$object$key)
keep_names <- lapply (keep_cols, function (i) grep (i, keys, value = TRUE))
keep_names <- sort (unique (unlist (keep_names)))
}

graph <- dplyr::left_join (graph, x$object_link_edge, by = "edge_") %>%
dplyr::select (-native_)
for (k in keep_cols) {
for (k in keep_names) {
objs <- dplyr::filter (x$object, key == k)
graph <- dplyr::left_join (graph, objs, by = "object_") %>%
dplyr::rename (!!dplyr::quo_name (k) := value) %>%
Expand Down
10 changes: 10 additions & 0 deletions R/weight-streetnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,16 @@ weight_streetnet.sc <- function (x,

x$vertex <- x$vertex [which (!duplicated (x$vertex)), ]

if (wt_profile == "bicycle") {
if (is.integer (keep_cols)) {
stop (
"keep_cols for 'sc' networks must be names of columns, not indices",
call. = FALSE
)
}
keep_cols <- unique (c (keep_cols, c ("^bicycle", "^cycleway")))
}

graph <- extract_sc_edges_xy (x) %>% # vert, edge IDs + coordinates
sc_edge_dist () %>% # append dist
extract_sc_edges_highways (
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"codeRepository": "https://github.com/ATFutures/dodgr",
"issueTracker": "https://github.com/ATFutures/dodgr/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.2.20.003",
"version": "0.2.20.004",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down

0 comments on commit 9dfbe61

Please sign in to comment.